Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

!important

Featured Replies

What is

!important

used for and when should I use it?

 

Thanks.

  • 2 weeks later...

Hi Meschach,

 

Coincidentally, the site that you've been helping me uses the "! important" rule. I used it to make the highlight the current page in the navigation menu. Here I've used the same style as for the hover state, but browsers refused to implement it until I added ! important because I'd already declared a style for the static links. In other words, ! important overrides existing style rules, something like this:

 

		 #nav li a:link, #nav li a:visited {
	  color: red;
	  }

	  #nav li a:hover {
	  color: blue;
	  }

	  .current {
	  color: blue ! important;
	  }

 

I then assigned the .current class to the "current" anchor:

<li><a href="directions.html" class="current">Google Map</a></li>

 

The ! important rule is also invaluable for print style sheets to override the 'screen' styles:

 

	 #nav, #header, #footer {
			  display: none;
			  }

	#container, #content, #rightcol {
			  width: 100% ! important;
			  margin: 0 !important;
			  }

 

 

Note that there should be a space between the exclamation mark and 'important'.

I hope this helps.

 

Marie

  • Author

Hmm... Why would you want to override existing ones rather than just making a new class?

 

Just curious..

Hmm... Why would you want to override existing ones rather than just making a new class?

 

Just curious..

 

I'd recommend not using it if it all possible! The only time (off the top of my head) I see a valid use of it is when you need to have a cross browser minimum height set for an element:

 

e.g, min-height: 100px; height: auto !important; height: 100px;

 

The more you start adding hacks like !important into your styles the less control you end up having over whats going on which invariably leads to more and more hacks needed to keep sites working across browsers. The extra time spent in working out exactly why things display differently in two different browsers (e.g FF and IE ) will save you loads of time wasted from the headaches of hacks!

  • Author
I'd recommend not using it if it all possible! The only time (off the top of my head) I see a valid use of it is when you need to have a cross browser minimum height set for an element:

 

e.g, min-height: 100px; height: auto !important; height: 100px;

 

The more you start adding hacks like !important into your styles the less control you end up having over whats going on which invariably leads to more and more hacks needed to keep sites working across browsers. The extra time spent in working out exactly why things display differently in two different browsers (e.g FF and IE ) will save you loads of time wasted from the headaches of hacks!

 

Thanks for the info.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.