Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 code element - language class

Tags:

html

The HTML5 <code> element has an optional class="language-" attribute to define the language of the code fragment. An example from the spec:

<pre><code class="language-pascal">var i: Integer;
begin
   i := 1;
end.</code></pre>

Is there a list of the languages to be used? Just thinking that otherwise there are likely to be multiple different spellings or interpretations of languages e.g. VB6 vs visual basic 6 etc.

like image 974
Kris C Avatar asked Jan 08 '12 12:01

Kris C


1 Answers

In the WHATWG’s HTML Living Standard version of the specification, it does actually recommend prefixing the value of class attributes on <code> elements with "language-*":

From the HTML Living Standard: Text-Level Semantics - the code element

There is no formal way to indicate the language of computer code being marked up. Authors who wish to mark code elements with the language used, e.g. so that syntax highlighting scripts can use the right rules, can use the class attribute, e.g. by adding a class prefixed with "language-" to the element.

(However, I would assume that this prefix has no real practical value – that would depend on whether real-world websites take up the convention and whether third-party tools detect and actually implement this prefix.)

like image 121
Jordan Clark Avatar answered Sep 18 '22 11:09

Jordan Clark