How to approach the situation with semantic markup and responsive design in mind?

Currently, I am developing a small website employing the mobile-first strategy. This means that I design for small screens first and then adapt as the screen size increases. To save space, I either show or hide certain information on the page or swap it out depending on the size of the screen. While this approach may appear visually appealing, it presents challenges when trying to maintain semantic markup.
Let's take a closer look at what I have accomplished thus far:

HTML

<header>
    <nav role="navigation">
        <a href="#navlist">☰</a>
        <a href="/">Page Title</a>
        <p class="hidden-s hidden-l">I the page's tagline</p>
        <ul id="navlist">
            <li><a href="/">Link 1</a></li>
            <li><a href="/">Link 2</a></li>
            <li><a href="/">Link 3</a></li>
            <li><a href="#">Close Menu</a></li>
        </ul>
    </nav>
</header>

<main role="main">
    <article>
        <header>
            <h1><a href="#">Blog Post 1</a></h1>
        </header>
        <p>Short excerpt of Blog Post 1</p>
    </article>
    <article>
        <header>
            <h1><a href="#">Blog Post 2</a></h1>
        </header>
        <p>Short excerpt of Blog Post 2</p>
    </article>
</main>

CSS

nav { background-color: rgba(255, 0, 0, .4); }

#navlist {
    display:none;
}

#navlist:target {
    display:block;
}

.hidden-s {
    display: none;
}

@media screen and (min-width: 500px) {
    .hidden-s {
        display: block;
    }
}

@media screen and (min-width: 700px) {
    .hidden-l {
        display: none;
    }
}

Fiddle

The current setup involves hiding the tagline on smaller screens, displaying it on medium-sized screens, and hiding it again on larger screens. The reason behind hiding the tagline on large screens is to allocate more space for additional information displayed in a different location especially on larger screens. Here is an overview:

HTML

<main role="main">
<div class="more-info">
    <header>
        <h1>Page Title</h1>
        <p>Some more info over the page you are reading.</p>
    </header>
</div>
<article>
    <header>
        <h1><a href="#">Blog Post 1</a></h1>
    </header>
    <p>Short excerpt of Blog Post 1</p>
</article>
<article>
    <header>
        <h1><a href="#">Blog Post 2</a></h1>
    </header>
    <p>Short excerpt of Blog Post 2</p>
</article>

CSS

.hidden-s,
.more-info {
    display: none;
}

@media screen and (min-width: 700px) {
    .hidden-l {
        display: none;
    }

    .more-info {
        display: block;
    }
}

Fiddle

An issue arises with the header element. Referring to the spec:

When the nearest ancestor sectioning content or sectioning root element is the body element, then it applies to the whole page.

By enclosing the nav within a header, it implies that the navigation and its contents apply to the entire page. However, I feel that this arrangement makes sense only for medium-sized screens where additional information is visible. On larger screens, the content inside .more-info serves as the page header. As for smaller screens, determining what to include within an <h1> becomes challenging.

I could insert the page title, but switching it to an image such as a logo would result in poor markup.

What would be the best course of action - should I integrate two header elements on the page? Although technically permitted, I am uncertain if it aligns well with the intended purpose in my scenario?

Answer №1

First off, I want to applaud your attention to detail when it comes to semantics in web development.

It is completely acceptable to have multiple <header> tags within a single page. Each <header> tag serves as the header area for its closest parent section, whether that be a <section>, or in your case, a <main>.

While using a <nav> tag in your main global header signifies that it is the primary navigation for your entire website, how you choose to style and display it at different screen sizes does not impact its semantic meaning.

Semantics are crucial in web design, but they should not overshadow the other essential aspects of your project. Don't stress too much about perfection in this area—focus on improving over time. There are plenty of other critical elements to consider, such as optimizing page load speed for improved SEO and ensuring high-quality content.

If you're interested in delving deeper into the topic, I recommend reading the article "SEO for Responsive Websites" by Smashing Magazine. You can find it here.

Answer №2

Avoid having multiple header elements on a single webpage, as it can confuse search engines that rely on the header to understand the content of your page. It is essential that the header clearly conveys the title of your page and its purpose. For optimal SEO performance, it is recommended to utilize an h1 element within the header to encapsulate the main heading or title of your page.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to incorporate line spacing using CSS

Is there a way to adjust the spacing between the drop down boxes in the sidebar so that they align neatly with the questions in my section? select { font-family: 'Courier New', monospace; color: black; font-weight: bold; font-size: 3 ...

Showing a picture in Angular from a stored image on a node.js server

I'm curious about security measures. Let's say I've uploaded an image of an animal to the server, such as 1545419953137bear.jpg, which is stored in my backend uploads folder along with other images. On the frontend, I use an img element wit ...

Retrieving a compilation of items found within text selected by the user on a website

Imagine a scenario in which a webpage contains the following structure: <p> <span class="1">Here's some text</span> <span class="2">that the user</span> <span class="3">could select.</span> </p> I ...

Accessing Local Data with Local HTML on Android - Error: File Not Found

After organizing my project in a folder within the main root directory, I successfully created a basic hello world project. The HTML file displays perfectly in Chrome, but trying to load files from the main project folder or subfolders results in a net::ER ...

Cross-origin resource sharing problem arises when JavaScript is loaded asynchronously using script tags created dynamically

By dynamically creating a script as shown below, the JavaScript source is downloaded asynchronously. let newScript = document.createElement('script'); newScript.src = srcUrl; let firstScript = document.getElementsByTagName('script')[0] ...

Effective URL structure with nested ui-view in AngularJS

It is common knowledge that Angular functions as a SPA (Single Page Application). I am seeking the most effective approach to display a main left-side menu selector page, where clicking on any menu item will load the content in the right-side view div. Th ...

Positioning close icon on Bootstrap 4 tab

I need help aligning a close icon for a BootstrapVue tab with Bootstrap 4.2 in the top right corner. Here is my code: <b-tab v-for="order in tabs" :key="order.id"> <template slot="title"> <span class="float-left">{{ order.nam ...

How can I customize the styling of Autocomplete chips in MUI ReactJS?

Trying to customize the color of the MUI Autocomplete component based on specific conditions, but struggling to find a solution. Any ideas? https://i.stack.imgur.com/50Ppk.png ...

Enhance Your Website by Integrating Slick Slider with Bootstrap 4

I am currently facing a significant issue. I am attempting to integrate three div elements into my slider, and all of them maintain a Bootstrap 4 structure. The code looks like this, and it is being generated from another Jquery function where I am inserti ...

What causes the disparity in functionality between CSS's Left 75% and Right 25% properties?

Here is my CSS code snippet: .bloodparam > .highvalue { bottom: 12px; right: 25%; } and .bloodparam > .highvalue { bottom: 12px; left: 75%; } I expected the element to be in the same position with both lines of code, but I'm noticing differe ...

Stop javascript function from automatically invoking itself

I am new to php and javascript and currently working on using a session variable to keep track of a counter. I want the counter to increment on the next button click and decrement on the previous button click. The issue I'm facing is with the JavaScri ...

What is the method to send an email with an embedded image using C# without the presence of ATT00001.bin file

Currently, I can successfully send emails using SMTP in C# and even include images as LinkedResource. However, the issue arises when recipients receive emails with ATT0000X.bin files attached. How can I prevent these bin files from being included in the em ...

Scroll on sidebar that overflows, rather than the page behind

My goal is to have a fixed background page while allowing the sidebar to scroll independently. Both elements are too large for the screen, so I want the page to scroll normally until the navbar overflows in height and becomes scrollable. Check out the exam ...

Creating various rows within a loop can be achieved by using conditional statements to determine

I am faced with a challenge of handling an array of images, among other properties, and I aim to achieve the following outcome: https://i.sstatic.net/BYajY.png As the images reach the end of the container (which fits 4 images on desktops and adjusts for ...

Error in URL parsing while using Jsoup on Android platform

Can anyone assist me in parsing an HTML site? I am trying to extract the image source and link to another page, but I keep getting an empty list. Here is my code: Elements elems2 = doc.select("div"); for (Element elem2 : elems2) { if (elem2.attr("clas ...

Increased Z-index on an unfamiliar site

I'm in the process of enhancing the Moodle platform at my school with a userscript, and I want to create a sleek UI for it. One feature I want to add is a progress bar that stays fixed at the top of the browser viewport so that it remains visible as ...

Having difficulty attaching elements to the bottom of a page

Kindly review the demo code provided. The issue is that when you scroll to the bottom, the stick to top element remains at the top as expected, but the stick to bottom element does not stick to the bottom as intended. Is there an error in the code? < ...

the best way to transfer a JavaScript value to a PHP page

I am experiencing an issue with an undefined function in my PHP page. I have tried everything and it just doesn't seem to work for me. Can anyone please assist me with this problem? <!DOCTYPE html> <html> <head> <scrip ...

Addressing see-through box styling in CSS

When working on a website using HTML and CSS, I encountered an issue with a transparent box. All elements within this box are also transparent, but I want them to be solid without any opacity. How can I resolve this? .parent { display: inline-block; ...

Avoiding Overlapping DIVs: Tips to Keep Your Elements in Place

Instead of using table-based layout, I have decided to go with a DIV-based layout in order to streamline the markup and improve page load speed. However, as I am not an expert in CSS, I find it quite challenging. Below are the CSS classes I am currently us ...