HTML For Beginners: Part 3

Introduction

 
Before reading this article please visit the following links:
HTML Attributes
  • HTML elements can have attributes
  • Attributes provide additional information about an element
  • Attributes are always specified in the start tag
  • Attributes come in name/value pairs like: name="value"
The language Attribute
  • The document language can be declared in the <html> tag.
  • The language is declared in the language attribute.
  • Declaring a language is important for accessibility applications (screen readers) and search engines
Example
  1. <!DOCTYPE html>    
  2. <html lang="en-US">    
  3.     <body>    
  4.         <h1>My First Heading</h1>    
  5.         <p>My first paragraph.</p>    
  6.     </body>    
  7. </html>   
    • The first two letters specify the language (en). If there is a dialect, use two more letters (US).
      The title attribute.
    • HTML paragraphs are defined with the <p> tag.
    Example
    1. <p title="c-sharpcorner">c-sharpcorner is a website in which the articles, blogs… etc are written on “TECHNOLOGY ”.    
    2. </p>  
    The href Attribute

    HTML links are defined with the <a> tag. The link address is specified in the href attribute.

    Example
    1. <a href="http://www.c-sharpcorner.com">This is a link</a>     
    Size Attributes
    • HTML images are defined with the <img> tag.
    • The filename of the source (src) and the size of the image (width and height) are all provided as attributes.
    Example
    1. <img src=" E:\Walls\HTML\c#corner.jpg" width="104" height="142”    

    The alt Attribute


    The alt attribute specifies an alternative text to be used when an HTML element cannot be displayed.
     
    The value of the attribute can be read by "screen readers". This way, someone "listening" to the webpage, in other words, a blind person, can "hear" the element.

    Example
    1. <img src=" E:\Walls\HTML\c#corner.jpg"alt="www.c-sharp corner.com" width="104" height="142” > 
    Always Use Lowercase Attributes
    • The HTML5 standard does not require lower case attribute names.
    • The title attribute can be written with an upper or lower case like Title and/or TITLE.
    • Lower case is the most common.
    • Lower case is easier to type.

    Summary

    • All HTML elements can have attributes.
    • The HTML title attribute provides additional "tool-tip" information.
    • The HTML href attribute provides address information for links.
    • The HTML width and height attributes provide size information for images.
    • The HTML alt attribute provides the text for screen readers.
    • Always use lowercase HTML attribute names.