AltSchool Of Engineering Tinyuka’24 Month 1 Week 4
We started the class with a revision of the previous class as usual with, Introduction to HTML, HTML document structure, importance of HTML and so on... You can go through the previous class here for more context this is what our instructor taught us this week. Understanding Semantic HTML Semantic HTML involves using HTML elements that reflect the meaning and purpose of the content, rather than focusing solely on how it looks visually. This approach enhances the clarity and structure of the content, making it easier for both users and machines—such as search engines and assistive technologies—to interpret. Prioritizing Meaning Over Appearance The key principle here is to select HTML elements based on their semantic significance. For instance, an tag should not be used merely for its default large and bold styling; instead, it should denote the primary heading or title of the content. By adhering to this practice, developers create more meaningful, accessible web pages that better serve user needs and improve search engine optimization. Non – Semantic Markup Example Semantic Markup one word one word one word one word five words three words forty-six words forty-four words five words Semantic Markup Example Semantic Markup one word one word one word one word five words three words forty-six words forty-four words five words Accessibility and Machine-Readability in Semantic HTML Semantic markup plays a crucial role in enhancing both accessibility and machine-readability of web content. For example, browser developer tools can illustrate how the Accessibility Object Model (AOM) interprets semantic versus non-semantic markup differently. Assistive technologies, such as screen readers, depend on the AOM to accurately understand the structure and meaning of the content. Roles and Landmarks Within semantic HTML, roles and landmarks are essential concepts. Elements like , , , and come with implicit roles that designate them as landmarks for assistive technologies. This designation allows users, especially those relying on screen readers, to navigate web content more efficiently. By using semantic elements, developers can significantly improve the user experience for individuals with disabilities, making websites more inclusive and easier to navigate. Using the Role Attribute in Semantic HTML While semantic elements come with built-in implicit roles, the role attribute can also be applied to any HTML element to designate a specific role. However, it is generally advised to use the appropriate semantic element rather than relying solely on the role attribute. For example: Three words one word Choosing the Right Elements The emphasis here is on selecting the most suitable HTML elements based on their semantic meaning and functionality, rather than their visual characteristics. Developers should consider questions like, "Which element accurately reflects the purpose of this section?" when constructing HTML. Utilizing semantic HTML is vital for enhancing accessibility, improving machine-readability, and providing a clearer structure and meaning to content. This practice not only benefits users but also contributes to better web development standards overall. HTML Elements for Structuring Content In HTML, various semantic elements help organize content effectively: : This element is used for introductory content at the top of a page, section, or article. It can include elements like logos, titles, and navigation menus. : This tag wraps major navigation blocks, such as menus, making it clear where users can find links to different sections of the site. : Representing the primary content area unique to a specific page, there should only be one element per page to clarify the main focus of that content. : Ideal for self-contained pieces of content, such as blog posts or news articles, which can be distributed or reused independently. : This element groups related content, such as chapters or parts of a guide, to create a logical structure within the document. : Used for content that is tangentially related to the main content, like sidebars or supplementary information, helping to keep the main flow distinct. : This tag is reserved for footer content, including copyright notices, contact details, or related links at the bottom of a page, section, or article. By using these semantic elements appropriately, developers can create well-structured, meaningful web pages that enhance both user experience and accessibility. HTML Attributes In HTML, there are two main types of attributes: Boolean attributes and Enumerated attributes. Boolean Attributes Boolean attributes are those that, when present, are always considered true. Examples include attributes like au
We started the class with a revision of the previous class as usual with, Introduction to HTML, HTML document structure, importance of HTML and so on... You can go through the previous class here for more context this is what our instructor taught us this week.
Understanding Semantic HTML
Semantic HTML involves using HTML elements that reflect the meaning and purpose of the content, rather than focusing solely on how it looks visually. This approach enhances the clarity and structure of the content, making it easier for both users and machines—such as search engines and assistive technologies—to interpret.
Prioritizing Meaning Over Appearance
The key principle here is to select HTML elements based on their semantic significance. For instance, an tag should not be used merely for its default large and bold styling; instead, it should denote the primary heading or title of the content. By adhering to this practice, developers create more meaningful, accessible web pages that better serve user needs and improve search engine optimization.
Non – Semantic Markup Example
Semantic Markup
one word
one word
one word
one word
five words
three words
forty-six words
forty-four words
five words
Semantic Markup Example
Semantic Markup
five words
three words
forty-six words
forty-four words
Accessibility and Machine-Readability in Semantic HTML
Semantic markup plays a crucial role in enhancing both accessibility and machine-readability of web content. For example, browser developer tools can illustrate how the Accessibility Object Model (AOM) interprets semantic versus non-semantic markup differently. Assistive technologies, such as screen readers, depend on the AOM to accurately understand the structure and meaning of the content.
Roles and Landmarks
Within semantic HTML, roles and landmarks are essential concepts. Elements like
, ,
, and
come with implicit roles that designate them as landmarks for assistive technologies. This designation allows users, especially those relying on screen readers, to navigate web content more efficiently. By using semantic elements, developers can significantly improve the user experience for individuals with disabilities, making websites more inclusive and easier to navigate.
Using the Role Attribute in Semantic HTML
While semantic elements come with built-in implicit roles, the role attribute can also be applied to any HTML element to designate a specific role. However, it is generally advised to use the appropriate semantic element rather than relying solely on the role attribute. For example:
Three words
Choosing the Right Elements
The emphasis here is on selecting the most suitable HTML elements based on their semantic meaning and functionality, rather than their visual characteristics. Developers should consider questions like, "Which element accurately reflects the purpose of this section?" when constructing HTML. Utilizing semantic HTML is vital for enhancing accessibility, improving machine-readability, and providing a clearer structure and meaning to content. This practice not only benefits users but also contributes to better web development standards overall.
HTML Elements for Structuring Content
In HTML, various semantic elements help organize content effectively:
: This element is used for introductory content at the top of a page, section, or article. It can include elements like logos, titles, and navigation menus.: This tag wraps major navigation blocks, such as menus, making it clear where users can find links to different sections of the site.
: Representing the primary content area unique to a specific page, there should only be one element per page to clarify the main focus of that content.
: Ideal for self-contained pieces of content, such as blog posts or news articles, which can be distributed or reused independently.
: This element groups related content, such as chapters or parts of a guide, to create a logical structure within the document.
: Used for content that is tangentially related to the main content, like sidebars or supplementary information, helping to keep the main flow distinct.
: This tag is reserved for footer content, including copyright notices, contact details, or related links at the bottom of a page, section, or article.
By using these semantic elements appropriately, developers can create well-structured, meaningful web pages that enhance both user experience and accessibility.
HTML Attributes
In HTML, there are two main types of attributes: Boolean attributes and Enumerated attributes.
Boolean Attributes
Boolean attributes are those that, when present, are always considered true. Examples include attributes like autofocus, checked, disabled, and required. If any of these attributes are included in an element, it signifies that the element is, for instance, disabled or required. Notably, the presence of the attribute alone suffices, and it does not require a value. For example:
All three variations indicate that the input is required.
Enumerated Attributes
Enumerated attributes, on the other hand, can be a bit confusing as they have a predefined set of valid values. If an enumerated attribute is present without a specified value, it defaults to a specific value. For instance, using the contenteditable attribute in a tag without a value:
This is equivalent to writing:
By understanding these attribute types, developers can use HTML more effectively, ensuring proper functionality and behaviour of web elements.
Overview of Global Attributes in HTML
Global attributes in HTML are flexible attributes that can be used with any HTML element, including those in the section. There are over 30 such attributes, but their effects can differ based on the specific element. For example, applying the hidden attribute to a
tag has no visible effect since meta content is not rendered on the page.
Important Global Attributes
- id: This attribute provides a unique identifier for an element, serving various functions such as:
Targeting a link’s fragment identifier.
Identifying elements for scripting.
Associating a label with form elements.
Offering descriptions for assistive technologies.
Enhancing CSS targeting specificity.
class: The class attribute allows for styling and targeting elements with CSS and JavaScript. It can hold a space-separated list of case-sensitive class names, which are particularly useful in frameworks and component libraries.
style: This attribute applies inline CSS styles directly to an element. Its value consists of property-value pairs, formatted like a CSS block. For example:
This text is red and 16 pixels in size.
- tabindex: The tabindex attribute can be added to any element to make it focusable. It defines the element's position in the tab order:
A negative value (like -1) allows focus via JavaScript but excludes it from the tab sequence.
A value of 0 makes the element focusable and part of the default tab order.
Positive values prioritize focus but are generally discouraged.
hidden: This attribute hides an element from view while keeping it in the DOM.
inert: This boolean attribute, when present, causes the browser to ignore user input events for the element and its children, including focus and interaction from assistive technologies.
lang: This attribute specifies the language of the element's content, improving accessibility and search engine optimization.
aria-*
(ARIA attributes): These attributes enhance accessibility for users with disabilities by providing additional semantic information about the elements, making it easier for assistive technologies to interpret the content.
Additional global attributes include dir, draggable, spellcheck, title, and accesskey. By effectively using these global attributes, developers can significantly improve the functionality, accessibility, and styling of their HTML documents.
Role Attribute
The role attribute enhances the semantic meaning of content, allowing screen readers to convey the expected user interactions. For example:
Three words
In this example, the roles clarify the structure and function of the elements for assistive technologies.
ARIA Attributes
WAI-ARIA attributes like aria-*
improve accessibility for users with disabilities. For instance, to create a checkable menu item, you can use the following code:
With CSS, you can style the checked state:
[aria-checked="true"] { font-weight: bold; }
[aria-checked="true"]::before { background-image: url(checked.gif); }
Contenteditable Attribute
The contenteditable attribute makes an element editable and focusable. It can take values like true or false, with a default of inherit when not specified. Here are equivalent ways to set the attribute: