HTML 包含了一系列的元素(elements),而元素包含了標籤(tags )與內容(content),我們用標籤來控制內容的呈現樣貌,例如字體大小、斜體粗體、 在文字或圖片設置超連結等。舉例來說,請看看以下這個句子:
My cat is very grumpy
如果我們想讓這個句子自成一個段落,那麼可以在它前後分別加上段落標籤 (<p>),它就變成一個段落元素了:
<p>My cat is very grumpy</p>
<p>My cat is very grumpy</p>
我們可以看到基本的架構:
元素還可以有「屬性(Attribute)」,請大家看看下面的例子:
<p class="editor-note">My cat is very grumpy</p>
屬性能提供更多的資訊(當然,這個資訊是幫助我們更有效及方便編輯,不會呈現在網頁上),屬性包含了屬性名稱與值,你可以利用屬性設定這個元素的色彩、對齊方式、圖表的格線等等。
例如這個句子:「我的貓有夠無敵臭臉」,若你想強調「有夠無敵」,我們就可以把「有夠無敵」這四個字自成一個顯示為粗體的元素 <strong> :
<p>我的貓 <strong>有夠無敵</strong>臭臉 。</p>
<img src="images/firefox-icon.png" alt="My test image">
它有兩個屬性,但是沒有結束標籤,也沒有裡面的內容。因為圖片元素是直接把圖檔嵌在 HTML 網頁上。
<!DOCTYPE html> <html> <head> <meta charset="big-5"> <title>My test page</title> </head> <body> 歡迎, 來到 HTML 世界! </body> </html>
我們可以看到:
<img src="images/firefox-icon.png" alt="My test image">
如同我們前面提到,圖片元素是直接把圖檔嵌在HTML網頁上,它是透過圖片來源(src ,source)這個屬性,提供了連到圖片檔案的路徑。
我們也可以加上alt (alternative) 這個屬性。在網頁瀏覽者無法正確看到圖片時,你希望對他們呈現什麼樣的說明文字。
例題:看效果
scheme://host.domain[:port]/path/filename
說明:Scheme | 訪問 | 用于... |
---|---|---|
http | 超文本傳輸協議 | 以 http:// 開頭的普通網頁。不加密。 |
https | 安全超文本傳輸協議 | 安全網頁,加密所有信息交換。 |
ftp | 文件傳輸協議 | 用於將文件下載或上傳至網站。 |
file | 您計算機上的文件。 |
Example: <a href="https://www.csie.ntu.edu.tw/~sylee/courses/basics/hello.htm">hello.htm</a>
hello.htm
<h1>Title</h1> <h2>Subtitle</h2> <h3>Subsubtitle</h3>
例題:hello2.htm
<html> <head> <title>Sample page </title> </head> <body bgcolor="#EFFFEF"> <!--改變網頁底色 <h3>Sample page</h3> <!--使用標題3 Hello, HTML World! <!--文本 </body> </html>
<a href="primer.htm"> An HTML Primer</A> | | | anchor link text associated
以下是實例 (看效果):
<a href="hello.htm" target="_blank">hello</a>
<a href="https://www.google.com.tw/" target="_blank">Google 台灣</a>
例題:在本頁文本的起點,建立定錨點 "top",如:
<a name="top" ></a>
再用本地鏈結到該點,如:
<a href="#top">Page Top</a>
<!-- CS U1430: Expert Systems -->
<pre> ... </pre>
&entity_name; 或 &#entity_number;如需顯示小於號,我們必須這樣寫:<或<或<
< < > > & & ampersand
<img src="underconstruction.gif" border=0 width=40 alt="[Under construction]">/a>
<video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> Your browser does not support the video tag. </video>
<audio controls> <source src="杯底不可飼金魚.mp3" type="audio/mpeg"> Your browser does not support the video tag. </audio>
<object width="100%" data="heading.html"></object>
<embed width="25%" height="20%" src="ch16_455.jpg">請注意, <embed> 元件沒有結束標記。 它不能包含替代文本。
使用 height 和 width 屬性來指定 iframe 的大小。
高度和寬度在預設情況下,以像素為單位指定:
<iframe src="demo_iframe.htm" height="200" width="300" title="Iframe Example"></iframe>或者您可以添加樣式屬性,並使用 CSS 的高度、寬度及其他屬性:
<iframe src="demo_iframe.htm" style="height:200px;width:300px;border:none;"></iframe>例題: iframe
要嵌入圖片,最好使用 <img> 標籤。
要嵌入 HTML,最好使用 <iframe> 標籤。
要嵌入視頻或音頻,最好使用 <video> 和 <audio> 標籤。
background-image:url("gif/gas.jpg");
<HTML> <HEAD> <TITLE> meta 標籤的使用:中文網頁 </TITLE> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5"> </HEAD> <BODY> 這是一個繁體中文網頁! (This page uses big5 character set.) charset=big5 </BODY> </HTML>
詳見語言編碼