HTML Attributes

Ratings:
(4)
Views: 1075
Banner-Img
Share this blog:

HTML Class Attribute

The class HTML attribute is used to associate an element with a style sheet, and specifies the class of element, you learn more about the use of the class attribute when you will learn cascading Style sheet(CSS). The value of the attribute may also be a space-separated list of class names. For example.

class=”className1   classname2   classname3”

HTML Style Attribute

The style HTML attribute  allows you to specify CSS rules within the element. For example

<p style=”font-family:arial; color:#FF0000;”>Some text… </p>

Generic Attributes

Here’s table of some other attributes that are readily usable with many of HTML’s tags.

Attribute Options Function
align right,left,center Horizontally aligns tags
valign top,middle,bottom Vertically aligns tags within an HTMl element.
bgcolor numeric, hexadecimal,RGB values Places a background color behind an element
background URL Places an background image behind an element
ID User Defined Names an element for use with cascading style sheets
Class User defined classifies an element for use with cascading style sheets
Width Numeric value Specifies the width of tables, images, or table cells
height Numeric value Specifies the height of tables, images,or table  cells
Title User Defined “Pop-Up” title for your element.

We will see related examples as we will proceed to study other HTML tags.

World wide web Consortium(w3c) recommends lowercase in HTML 4, And demands lowercase tags in XHTML

Attributes

An attribute is used to define the characteristics of an element and is placed inside the element’s opening tag. All attributes are made up of two parts: a name and a value.

The value of the attribute should be put in double quotation marks, and is separated from the name by the equals sign

Many HTML tags have a unique set of their own attributes. Right now we want to focus on a set of generic attributes.

Core Attributes

The four core attributes that can be used on the majority of HTML elements(although not all) are:

  • id
  • title
  • class
  • style

HTML id Attribute

The id HTML attribute can be used to uniquely identify any element within a page(or style sheet). There are two primary reasons that you might want to use an id attribute on an element:

If an element carries an id attribute as a unique identifier it is possible to identify just that element and its content.

If you have two elements of the same name within a webpage(or style sheet), you can use the id attribute to distinguish between elements that have the same name.

For now, the id attribute could be used to distinguish between two paragraph elements, like so:

<p id=”html”> This para explains what is HTML</p>

<p id=”css”>This para explains what is casecading style sheet<\p>

Note that there are some special rules for the value of the id attribute, it must :

Begin with a letter (A.Z or a.z) and can then be followed by any number of letters, digits(0,9), hyphens, underscores, colons, and periods.

Remain unique within that document; no two attributes may have the same value within that HTML document.

HTML Title Attribute

The title HTML attribute gives a suggested title for the element. The behavior of this attribute will depend upon the element that carries it, although it is often displayed as a tooltip or while the element is loading. 

Use Lowercase Attributes

Attribute names and attribute values are case-insensitive.

However, the World Wide Web Consortium(w3c) recommends lowercase attributes/attribute values in their HTML 4 recommendation.

Newer versions of (X) HTML will demand lowercase attributes.

You liked the article?

Like: 0

Vote for difficulty

Current difficulty (Avg): Medium

EasyMediumHardDifficultExpert
IMPROVE ARTICLEReport Issue

About Author

Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.

Stay Updated
Get stories of change makers and innovators from the startup ecosystem in your inbox