HTML <nav> style Attribute

A style attribute on a <nav> tag assigns a unique style to the element.

Its value is CSS that defines the appearance of the nav element.



A style attribute on a <nav> element.

<nav style="background: indigo; padding: 10px; text-align: center; font-size:16px;">
  <a style="color:white;margin-right:20px;" href="javascript:alert('Home was clicked')">Home</a>
  <a style="color:white;margin-right:20px;" href="javascript:alert('Gallery was clicked')">Gallery</a>
  <a style="color:white;margin-right:20px;" href="javascript:alert('Contact Us was clicked')">Contact Us</a>
  <a style="color:white;margin-right:20px;" href="javascript:alert('About was clicked')">About Us</a>

Using style

The style attribute specifies the style, i.e. look and feel, of the <nav> element.

A style contains any number of CSS property/value pairs, separated by semicolons (;).

The style attribute overrides any other style that was defined in a <style> tag or an external CSS file.

This inline styling affects the current <nav> element only.


<nav style="CSS-styles">



Value Description
CSS-styles One or more CSS property/value pairs separated by semicolons (;).

More Examples

A style attribute on a <nav> element.
Clicking the button will align the links vertically.

  .nav {display:flex;background:indigo; padding: 8px 20px;}
  .nav a {margin: 5px 20px; font-size:16px; color:white; text-decoration:none;}

<nav id="mynav" style="flex-direction: row;" class="nav">
  <a href="javascript:alert('Home was clicked')">Home</a>
  <a href="javascript:alert('Gallery was clicked')">Gallery</a>
  <a href="javascript:alert('Contact Us was clicked')">Contact Us</a>
  <a href="javascript:alert('About was clicked')">About Us</a>

<br />
<button onclick="toggle();">Toggle style</button>

  let toggle = () => {
    let element = document.getElementById("mynav");

    if ( === "row") { = "column";
    } else { = "row";

Code explanation

The style attribute assigns a layout of the <nav> element.

Clicking the button calls JavaScript, changing the layout of the <nav> to vertical.

Browser support

Here is when style support started for each browser:

6.0 Sep 2010
4.0 Mar 2011
9.0 Mar 2011
11.0 Dec 2010
5.0 Jun 2010

You may also like

 Back to <nav>

Last updated on Sep 30, 2023