What is HTML?
- Hypertext means text with hyperlinks.
- Syntax:
<! DOCTYPE html>
<html>
<head>
<title > This is tittle </title>
</head >
<body >
This is Body..
</body >
</html >
- Markup language annotates the text ( Differentiate heading and paragraph)
- Those annotations are nothing but Tags.
- Tag for paragraph is eg: <p></p> This is my paragraph
- Most of the tags follow the above pattern except Empty tags.
- Example for the empty tags is <hr> (Horizontal rule ) tag. Or we can use like <hr/>
- Every tags can have attributes , attributes carry the data to tag.
- Eg : <input type = “checkbox” />
- In the above example we created a check box and here tag in input and attribute is type.
- <! - - This is how we can write comments in html - ->
- Both are the same, and appear the same in the browser, because of white spaces are converted into single space.
<p> This is text </p> and
<p> This
Is
Text
</p>
- Boiler plate of html code is
<! DOCTYPE html>
<html>
<head>
<title > This is my website </title>
</head >
<body >
</body >
</html >
Semantics HTML:
- Does HTML make sense without a browser ? When we code the html we need a way to understand how tags are grouped ? Are they really grouped as we wanted ?
- Semantic markup is important because tags provide the content structure not the layout or style.
Tag |
Meaning |
|
- To write different articles , check this example
- https://www.w3schools.com/tags/tag_article.asp
|
|
- Thematic grouping of content.
- The <section> tag defines a section in a document.
- https://www.w3schools.com/tags/tag_section.asp
|
|
- Introductory, has sub tags h1, h2, h3
|
|
- Example which shows article , section , header and main
- https://www.w3schools.com/tags/tag_main.asp
|
|
- To have a set of navigation links
- https://www.w3schools.com/tags/tag_nav.asp
|
|
- The <aside> tag defines some content aside from the content it is placed in.
- https://www.w3schools.com/tags/tag_aside.asp
|
|
- https://www.w3schools.com/tags/tag_footer.asp
|
Tag |
Meaning |
|
- Paragraph tag, not only text we can add images between the open and closing tag
|
- <h1> primary heading </h1>
|
- Headings. There are also <h2> , <h3> , <h4>,<h5>, <h6>
|
- <img src = “cat.png” alt = “dogText” />
|
- Image tag has an src attribute which takes the path of the image. If that image is not there it will print the alternate text provided in the alt attribute.
- Relative Path: If the image is on our system
- Absolute Path: this is actual path of image
- The alt attribute can also be used to provide text to image when the internet is slow or the image is not able to load with the internet speed. We show this text to the user.
|
- <ol>
- <li> list item 1 </li>
- <li> list item 2 </li>
- </ol>
|
- Ordered list. <ol>
- Will contain <li> tag for every row, simply it is a list item. </li>
- By default, browser will show bullet list for <ol> </ol>
|
- <ul>
- <li> list item 1 </li>
- <li> list item 2 </li>
- </ul>
|
- UnOrdered list. <ul>
- Will contain <li>tag for every row
- By default, browser will show number list for <ul>
|
|
- Line break in the page
- It is also called as self closing tag
|
|
- Horizontal line - it is a thematic break and has semantic meaning.
- Browsers will draw a line between two different components to differentiate them.
|
- <a href = “https:google.com” > Google </a>
|
- Used to create the link
- Anchor tag, it has href attribute which stores the url. Used to provide urls
- Target attribute - allows user to open the window in a new page
- target=”_blank” - open in a new tab.
|
- <p> This is <em> important </em> dude </p>
|
- Text font style
- Emphasis tag shows the text inside with italics
|
- <p> This is <bold> important </bold> dude </p>
|
- Text font style
- bold tag highlights the text in it.
|
Creating a table in HTML
Tag |
Meaning |
- <table>Table</table>
- <tr>Table row tag</tr>
- <th>Table header tag</th>
- <td>Table data tag</td>
Attributes: for table header
- Scope <th span =”row’’>This becomes the
heading of the tabel row <th></th>
- ColSpan
|
- Table
- Table row
- Table header
- Table data
Attributes: for table header
- Defines the heading for row / col for proper alignment
- Defines for how many columns this heading is for ?
|
Tag |
Meaning |
- <thead><tr><th>NAME</th></tr>
- </thead>
- <tbody><tr><td>nitya</td></tr>
- <tfoot><tr><th span = “row”>Total</th><td>100</td></tr>
- <caption></caption>
- <colgroup></colgroup>
|
- Similar to the <th> tag, which is used in the standard semantic grouping tag’s
- This contains the main body or the table items within a table like <td></td>
- To represent the total or something like showing total we use <tfoot></tfoot>
- This is a caption or title for table
- This is used to group the columns
|
Tag |
Meaning |
- <form></form>
- <input></input>
- <label></label>
- <button></button>
- <fieldset></fieldset>
- <legend></legend>
Attributes for input tag:
- Type: text,button,checkbox…..
- Id
- Placeholder
Attributes for label tag:
- For attribute
|
- Form: The form tag is the wrapper around all the inputs or widgets
- Input: This is the generic tag that contains all kinds of inputs that we need
- Label: This is used to tell the user what kind of input they should type in input
- Button: Creates the button
- Fieldset: Gives the section for data mentioned within
- Legend: Can write the text in between the box line
- Type: We define what kind of input we want using type attribute
- Id: To make the input unique and use this id value in the label value to make the browser understand.
- Placeholder: To make the user understand, what kind of input or input format should look like/ we are expecting.
- For: This attribute will make the browser understand, for which input tag the particular label belongs to.
|
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Forms</title>
</head>
<body>
<form>
<label for="username"> Username</label>
<input id="username" minlength="6" type="text" name="username" placeholder="Username">
<label for="password"> Password</label>
<input id="password" minlength="6" required="required" type="password" name="password" placeholder="Password">
<input type="date" name="date">
<fieldset>
<legend> Choose your animal</legend>
<label for="dog"> dog</label>
<input type="radio" id ="dog" name="dog" value="dog">
<label for="cat"> car</label>
<input type="radio" id ="cat" name="cat" value="cat">
</fieldset>
<input type="submit" value="Login">
</form>
</body>
</html>
Document object model (DOM):
- First our browser receives our html in the form of text file and then it converts the file to DOM
- DOM is the tree like representation of the contents of the HTML FILE as a node
- HTML file ( received as text) —-> Browser ( parses the html file into DOM tree).
- The parsed DOM tree can be accessed by the API in javascript.
Accessibility:
- Accessibility refers to the people using the internet in different ways as well as people with different abilities.
- Accessibility allows us to build websites for everyone
- In this cases many users will be using an assistive technologies like screen reader to interact with the website
- These assistive technologies do not interact with the DOM directly instead they interact with the accessibility tree
-
Accessibility Tree: This is something very similar to the DOM tree which contains content/information for accessibility.
- We represent this tree with nodes.
- Nodes have four main components: name, description, role and state
- We know that the HTML file is converted to DOM -> DOM (this DOM is converted to actual UI) -> UI(this will be shown to the end-user) -> User. But this is not the case all the time.
- The DOM is actually splitted in two i.e one is converted to UI and the other one into accessibility tree which is used for this assistive technologies.
- So this is how users take input in two different ways.
-
Writing accessible HTML:
- We should use the descriptive context, tables & alt attributes
- We should use semantic elements
- Test the keyboard controls.Ensuring that the user is able to navigate to the all the major parts of the website using any one of the key on the keyboard
- WAI - ARIA : Web accessibility Initiative - Accessible Rich Internet Applications - Written by WSC —> It provides more attributes that we can use in HTML to further describe our content.
- Roles: What an element does.
- Properties: Extra meaning.
- States: Current state
- ARIA Roles : Divided into a variety of different categories.
- LandMark Roles:
- These are Major content areas or navigational landmarks. Sometimes these are what the user will navigate to first using assistive technology.
- Ex: Banners, main, navigation.
- Structure Roles:
- These roles are very similar to landmark roles and they define the structure of the page.
- Ex: tooltip, a list, or a table
- Widget Roles:
- These roles identify the interactive elements.
- Ex: tab, search box, button
- Window Roles:
- Window roles create sub-windows within the browser. So this removes some content from the rest of the page
- Ex: Dialog and alert dialog
- Live Regin Roles:
- Dynamic context changes
- Ex: timer, log, alert
-
ARIA Attributes:
- This attribute defines some live content i.e dynamically changing content and how important it is.
- Off: Don't announce changes.
- Polite: Announce changes when idle
- Assertive: Announce changes as soon as possible
- Aria-label: label not visible on UI
- Aria-labelledby: Another element as a label, passed by ID
- Aria-description: more detail than labels
- This <meta> tag is used to give the extra meta information about the web page
- This meta tags will use name and content pairs for type of metadata and its value
- Charset -> used to determine the character encoding of the website.
- UTF-8 -> it has all the languages.
- Name - name of the metadata