說明:HTML

本頁使用了標題或全文手工轉換
維基百科,自由的百科全書

要使用HTML代碼,無需額外處理,直接輸入HTML標記即可。


例子

span

<span>是通用行內文字容器,目前可以預設使用。span可以使用id、class、style來定義樣式:

<span style="color:red">style</span>
<span id="randomfooid">id</span>
<span class="importantmessage">class</span>

生成:

style id class

短語元素

span元素是用來對行內元素進行分組,以便通過樣式對它們進行格式化。它本身沒有任何意思。而短語元素是專門為有特殊意義的文字內容而設。

各短語元素的定義
<em> 呈現為強調後的文字。
<strong> 定義重要的文字。
<dfn> 定義一個定義專案。
<code> 定義電腦代碼文字。
<samp> 定義樣本文字。
<kbd> 定義鍵盤文字。它表示文字是從鍵盤上鍵入的,常用在電腦相關文件或手冊中。
<var> 定義變數。您可以將此標籤與<pre><code> 標籤配合使用。
<cite> 定義參照。可使用該標籤對參考文獻的參照進行定義,比如書籍或雜誌的標題。

短語元素同樣可以用class、id、style來定義樣式。 例如:

<em>Default </em>
<em style="color:red;font-style:normal">CSS style</em>

生成

Default CSS style

這不僅僅吸參照戶的注意力,還可以提醒使用非視覺化瀏覽器或有視力障礙的使用者。

font

注意,此元素不推薦使用,而以<span>替代。

對於一些屬性,比如顏色、字體、大小,只能這麼用:

<font size="200%">大</font>
<font color="red" face="標楷體">紅</font>字和
<font color="#0000ff" face="Comic Sans MS">Blue</font> text。

生成

字和 Blue text

div

<div>元素定義HTML文件中的分隔(division)或部分(section)。 <div>元素常用於組合塊級元素,以便通過樣式表來對這些元素進行格式化。 例如讓多組文字以紅色顯示,可以這麼運用:

 <div style="color:red">
  <p>This is a sentence.<em> This is an emphasized text.</em></p>
  <p>This is a paragraph.</p>
 </div>

生成

This is a sentence. This is an emphasized text.

This is a paragraph.

過時的HTML

新一代HTML的設計是盡量僅包含結構和內容,樣式的顯示就交由CSS負責。所以,有些HTML元素和屬性已經過時,甚至新版HTML不再支援。儘管這些過時的HTML元素和屬性在流行的瀏覽器仍然有效,但鼓勵編輯者使用新規格的HTML來編寫頁面。如果要定義文字的樣式,可以用style屬性來加入CSS。

過時的HTML元素 替代的HTML元素 意思
<font></font>
<span><span>
定義文字效果。亦可使用{{font}}{{color}}等模板。
<s></s>
<del></del>
<span style="text-decoration: line-through; "></span>
添加刪除線。
<center></center>
<div style="text-align: center; "></div>
<div style="width: auto; margin-left: auto; margin-right: auto; "></div>
置中文字,也可以使用模板{{Center}}
<big></big>
<span style="font-size: large; "></span>
或使用{{big}}等模板
放大文字。
<small></small>
<span style="font-size: small; "></span>
或使用{{small}}{{smaller}}等模板
縮小文字。注意:如果此標籤是用來表示注釋等內容的,則不是過時的。
<strong></strong>
<b></b>
<span style="font-weight: bold; "></span>
加粗文字。如果加粗文字是為了強調內容,則不是過時的。
<u></u>
<span style="text-decoration: underline; "></span>
添加底線,但是非超連結文字不應添加。


過時的HTML屬性 替代的CSS屬性
face="字體" font-family: 字體;
color="顏色" color: 顏色;
bgcolor="顏色" background-color: 顏色;
size="大小" font-size: 大小;
align="水平位置" text-align: 水平位置;

接下來從Sanitizer.php摘錄的原始碼附加的說明了什麼屬性是可用的。

 /* private */ 
 function removeHTMLtags( $text )
 {
  wfProfileIn( "OutputPage::removeHTMLtags" );
  $htmlpairs = array( # Tags that must be closed
   "b", "i", "u", "font", "big", "small", "sub", "sup", "h1",
   "h2", "h3", "h4", "h5", "h6", "cite", "code", "em", "s",
   "strike", "strong", "tt", "var", "div", "center",
   "blockquote", "ol", "ul", "dl", "table", "caption", "pre",
   "ruby", "rt" , "rb" , "rp"
  );
  $htmlsingle = array(
   "br", "p", "hr", "li", "dt", "dd"
  );
  $htmlnest = array( # Tags that can be nested--??
   "table", "tr", "td", "th", "div", "blockquote", "ol", "ul",
   "dl", "font", "big", "small", "sub", "sup"
  );
  $tabletags = array( # Can only appear inside table
   "td", "th", "tr"
  );

  $htmlsingle = array_merge( $tabletags, $htmlsingle );
  $htmlelements = array_merge( $htmlsingle, $htmlpairs );

  $htmlattrs = array( # Allowed attributes--no scripting, etc.
   "title", "align", "lang", "dir", "width", "height",
   "bgcolor", "clear", /* BR */ "noshade", /* HR */
   "cite", /* BLOCKQUOTE, Q */ "size", "face", "color",
   /* FONT */ "type", "start", "value", "compact",
   /* For various lists, mostly deprecated but safe */
   "summary", "width", "border", "frame", "rules",
   "cellspacing", "cellpadding", "valign", "char",
   "charoff", "colgroup", "col", "span", "abbr", "axis",
   "headers", "scope", "rowspan", "colspan", /* Tables */
   "id", "class", "name", "style" /* For CSS */
  );

比如元素<a>在維基代碼中被禁止使用,因此

<a href="https://meta.wikimedia.org/wiki/Main_Page">Main Page</a>

生成

<a href="https://meta.wikimedia.org/wiki/Main_Page">Main Page</a>

是文字而不是連結。

解析器擴充標籤

MediaWiki軟體加入了一批與HTML標籤類似的解析器擴充標籤,其中解析器標籤(Parser tag)由MediaWiki定義,而擴充標籤由擴充程式提供。Special:版本資訊列有所有標籤。欲知擴充標籤用法,可在Special:版本資訊搜尋對應的擴充程式,或者點擊下面的連結。

解析器標籤(Parser tag)

<gallery>, <nowiki>, <pre>

擴充標籤:

<categorytree>, <charinsert>, <hiero>,<imagemap>,<inputbox>, <math>, <poem>, <ref>, <references>,<syntaxhighlight> (也可寫作<source>), <timeline>

外部連結