Click here to Skip to main content
15,903,385 members
Articles / All Topics

Global Attributes - Part 1

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
26 Apr 2016CPOL1 min read 4.3K  
Global Attributes (Part 1)

There are some attributes that can be used on any element (including undefined elements); these are called 'Global Attributes' and they are used just like every other attribtute.

HTML
<element attribute-name="attribute-value"> </element>

The id Attribute

The id attribute is a unique identifier for an element. It can be used to refer to the element in CSS or JavaScript.

The only constraints the id attribute has is that it must be unique, contain at least one character and not contain any spaces. Everything else is perfectly valid.

The title Attribute

The title attribute represents advisory information (such as in a tooltip), but you should ensure that you do not rely on the title being visible as many user agents do not make it sufficiently available (e.g., web browsers on a smart phone).

The title attribute is inherited from the elements parent unless overridden.

The lang Attribute

The lang attribute specifies the language of the element and is inherited from the elements parent unless overridden.

The lang attribute should be specified using a 'BCP 47' code, e.g., jp for Japanese.

The translate Attribute

The translate attribute is used to specify if the elements content should be translated if the page is localised.

By default, the translate attribute is set to 'inherit' which means that the element should only be translated if its parent should be translated.

The root element defaults to 'yes' so unless it is specifically overridden, all elements will be translated when the page is localised.

In various cases, this would be incorrect behaviour, such as when you have a website devoted to comparing Japanese and English text.

In those situations, you should set the translate attribute of the relevant attributes to 'no'.

This article was originally posted at http://www.jflanagan.co.uk/feeds/posts/default

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --