Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 8179

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T10:43:08+00:00 2024-11-28T10:43:08+00:00

Helping Older Browsers Understand HTML5

  • 60k

Table of content

  • Introduction
  • Ancient browsers that do not support HTML5
  • How do these browsers interpret HTML5 semantic elements?
  • Okay, so what's the solution?

Introduction

When HTML5 was released it brought semantic HTML elements to the table which in turn frequently replace the famous divs and spans that are notoriously used everywhere.

The use of these semantic elements is very important, some of the reasons behind that being:

  • Offering people with disabilities a better navigation experience by creating a clear hierarchy of the content of the page for screen readers to parse.
  • Helps your website's SEO ranking (Search Engine Optimization) by facilitating the indexing of the website by search engines.
  • HTML elements now give a descriptive meaning to their content. An aside is a lot more descriptive than the general-everywhere-use of div or span.

Ancient browsers that do not support HTML5

Unfortunately though, not all browsers support HTML5 features (fully and/or partially) and that complicates things.

We can't write our HTML twice; one that is semantic for browsers that are compatible and one for the older versions that are not. Because that is resource consuming in terms of authoring and maintenance.

And we obviously cannot neglect the ones that do use ancient browsers (yes, some people do, surprisingly) because that could potentially mean decrease in revenue and visibility since a portion of people won't be able access our website properly.

Now these cursed browsers are (partial to no compatibility for semantic HTML):

  • Mozilla Firefox version 2 to 20
  • Google Chrome version 4 to 25
  • Safari version 3.1 to 6
  • Internet Explorer version 6 to 9

How do these browsers interpret HTML5 semantic elements?

That's a good question, it's an edge case that needs to be treated.

Naturally, incompatible browsers with HTML5 features won't recognize the new semantic elements like nav, header, footer etc.

So how do they parse them?

Browsers treat them as inline elements. Meaning they would go with the flow of text, they do not start a new line (the same default behavior of img and span for example).

Okay, so what's the solution?

  • ### The “meh” approach

Some of the older browser versions allow CSS rules to be associated with semantic elements (for example IE9 was the first of IE to adopt this), we will be using that to our advantage.

All you have to do is select the semantic elements and change their display (from inline as we said) to block.

An example:

header, section, footer, aside, nav, article, figure {   display: block; } 
Enter fullscreen mode Exit fullscreen mode

This is not the optimal solution nor the recommended one, it's meh.

  • ### The recommended approach

We get JavaScript involved in the play by fundamentally creating the elements from scratch as such:

document.createElement('nav'); document.createElement('header'); document.createElement('article'); // etc 
Enter fullscreen mode Exit fullscreen mode

By the way, this code must be appended in the head element either by linking to an external script or by writing the code inline using script tag.

The problem with this though is there's more than 100 semantic HTML element in the spec. And this code seems pretty lacking and is not reliable on real world projects.

The best way to deal with this is by using html5shiv (there's actually a funny story behind the debate whether it should be called shiv or shim).

The script is in this repo.

There are two ways to get the script (you can check them out in README of the repository), either by using Bower or manually installing it.

I prefer the manual installation via this link:

  1. After extracting the ZIP file, copy either files dist/html5shiv.js or dist/html5shiv-printshiv.js to your project's directory.
  2. Include the copied script in the head element
  3. Add this comment in the head element after all the stylesheets:
<!--[if lt IE 9]>   <script src="bower_components/html5shiv/dist/html5shiv.js"></script> <![endif]--> 
Enter fullscreen mode Exit fullscreen mode

Problem solved. You can now safely forget about the older browsers!

Thank you for reading!

I hope you learned something new and enjoyed reading!

Follow my blog and my Twitter for more!

Have a nice one.

Photo by Michael Dziedzic on Unsplash

beginnershtmlprogrammingwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.