CSS The !important Rule

CSS is the language we use to style an HTML document.
CSS describes how HTML elements should be displayed.
This tutorial will teach you CSS from basic to advanced.
Post Reply
Guest

CSS The !important Rule

Post by Guest »

CSS The !important Rule


What is !important?
The !important rule in CSS is used to add more importance to a property/value than normal.
In fact, if you use the !important rule, it will override ALL previous styling rules for that
specific property on that element!
Let us look at an example:

Example

#myid {  background-color: blue;}.myclass { 
background-color: gray;}p {  background-color: red !important;}
Try it Yourself »

Example Explained
In the example above. all three paragraphs will get a red background
color, even though the ID selector and the class selector have a higher
specificity. The !important rule overrides the
background-color property in both cases.

Important About !important
The only way to override an !important
rule is to include another !important
rule on a declaration with the same (or higher) specificity in the source code - and here the problem starts!
This makes the CSS code confusing and the debugging will be hard, especially if
you have a large style sheet!
Here we have created a simple example. It is not very clear, when you look at
the CSS source code, which color is considered most important:

Example

#myid {  background-color: blue !important;}.myclass { 
background-color: gray !important;}p {  background-color: red !important;}
Try it Yourself »

Tip: It is good to know about the !important
rule. You might see it in some CSS source code.
However, do not use it unless you absolutely have to.







Maybe One or Two Fair Uses of !important
One way to use !important is if you have to override
a style that cannot be overridden in any other way. This could be if you are
working on a Content Management System (CMS) and cannot edit the CSS code.
Then you can set some custom styles to override some of the CMS styles.
Another way to use !important is: Assume you
want a special look for all buttons on a page. Here, buttons are styled with a gray
background color, white text, and some padding and border:

Example

.button {  background-color: #8c8c8c;   color: white; 
padding: 5px;  border: 1px solid black; }
Try it Yourself »

The look of a button can sometimes change if we put it inside another element with
higher specificity, and the properties get in conflict. Here is an example of this:

Example

.button {  background-color: #8c8c8c;   color: white; 
padding: 5px;  border: 1px solid black; }#myDiv a { 
color: red;  background-color: yellow; }
Try it Yourself »

To "force" all buttons to have the same look, no matter what, we can add the !important
rule to the properties of the button, like this:

Example

.button {  background-color: #8c8c8c !important;   color: white
!important; 
padding: 5px !important;  border: 1px solid black !important; }#myDiv a { 
color: red;  background-color: yellow; }
Try it Yourself »














+1

Reference: https://www.w3schools.com/css/css_important.asp
HexZero
Posts: 3
Joined: Mon Oct 20, 2025 5:37 pm

Re: <t>CSS The !important Rule</t>

Post by HexZero »

God kväll! Såg en banner på en tågsajt när jag pendlade till Lund och bestämde mig för att kolla upp sidan. Jag hade haft en riktigt dålig period med spelandet och funderade på att sluta helt. Men när jag började spela hos https://swiper.com.se/ vände turen direkt. Jag vann en stor summa på poker som gjorde att jag täckte alla mina förluster. Nu känner jag mig nöjd och glad över att turen äntligen hittade tillbaka till mig i Sverige.
lavendercherida
Posts: 0
Joined: Fri Jun 05, 2026 11:58 am

Re: <t>CSS The !important Rule</t>

Post by lavendercherida »

I’m not a hero. I’m a cashier at a twenty-four-hour gas station. The kind with bulletproof glass and a bathroom that requires a key. My job is to scan candy bars and watch people buy cigarettes. It’s not glamorous. It’s not important. Most nights, I’m invisible—just a voice behind a speaker, telling people which pump is open.

Last month, I did something important. Not on purpose. Just by being there. And by having a phone.

It was a Tuesday. 3 AM. The store was dead. I was restocking the coffee station—nobody drinks coffee at 3 AM, but my manager likes things full. A guy walked in. Not unusual. What was unusual was his face. Pale. Sweating. Eyes wide like he’d seen something terrible.

I asked if he was okay. He didn’t answer. Just walked to the back of the store, stood in front of the potato chips, and stared at them like they held the secrets of the universe.

I watched him for a minute. Then I walked over. “Hey, man. You need help?”

He turned to me. His hands were shaking. “I’m stuck,” he said. “My car broke down. Two miles up the highway. I have no phone. No money. No way home.”

I’ve heard a lot of stories working the night shift. Most of them are lies. But this guy’s eyes weren’t lying. He was scared. Cold. Alone.

“Where’s home?” I asked.

“Three hours away. My daughter’s birthday is tomorrow. I was trying to make it. Now I’m here.” He laughed. A sad, broken laugh. “I don’t even have money for a tow truck.”

I wanted to help. But I’m a cashier. I make minimum wage. I had maybe forty dollars in my checking account. Not enough for a tow. Not enough for a hotel. Not enough for anything.

Then I remembered my phone.

I’d been playing on an online casino during my breaks. Nothing serious. Small bets. A few dollars here and there. The site worked great on my phone—fast, smooth, no glitches. I’d deposited twenty dollars a week ago and turned it into thirty-five. Not a fortune. But something.

I pulled out my phone. Opened the vavada mobile site. My balance was thirty-eight dollars. Not enough to save this guy. But maybe enough to try.

“Give me ten minutes,” I said.

He looked confused. “What?”

“Just wait,” I said. “I’m going to try something.”

I sat on the stool behind the register. Opened a game of blackjack. Low stakes. Two dollars a hand. I played fast. Faster than usual. I didn’t have time for slow and careful. I had a stranger in my store, counting on me for no good reason.

Won a hand. Lost a hand. Won two hands. Lost one. My balance climbed to forty-two dollars. Too slow.

I switched to roulette. Bet five on red. Won. Bet five on black. Won. Bet ten on odd. Won. My balance jumped to sixty-seven dollars.

I kept going. Bet twenty on red. Lost. Bet twenty on black. Won. Bet forty on red. Lost. My balance dropped to forty-five. I was getting nowhere. The guy was watching me, not understanding, just hoping.

I switched back to blackjack. Bet ten dollars a hand—reckless, stupid, not my style. Won. Bet ten again. Won. Bet ten again. Blackjack. Fifteen dollar profit. My balance hit seventy dollars.

I cashed out sixty. Left ten in the account. The withdrawal hit my PayPal in fifteen minutes. I transferred it to my bank account, then pulled sixty dollars in cash from the register—I’d replace it with my own money later.

I walked to the guy. Handed him the cash. “There’s a tow truck company two blocks down,” I said. “They open at 6 AM. Use this to get your car to a shop. The rest is for a bus ticket.”

He stared at the money. Then at me. “Why?” he said.

“Because it’s your daughter’s birthday,” I said. “And I have a phone.”

He cried. Right there in front of the potato chips. Big, ugly, grateful tears. I patted his shoulder. Made him a coffee. Let him sit in the back room until morning. When the tow truck came, he shook my hand and said, “I’ll pay you back.”

“Don’t,” I said. “Just go see your daughter.”

He left. I went back to work. Scanned candy bars. Watched people buy cigarettes. Felt different. Lighter. Like I’d done something that mattered.

The vavada mobile site was still open on my phone. My balance was ten dollars. I didn’t touch it for the rest of my shift. Just looked at it sometimes. A reminder. Not of the win—of the reason. The stranger. The birthday. The chance to be someone’s hero, even for one night.

I never saw him again. He didn’t come back to pay me. I didn’t expect him to. That wasn’t why I did it. I did it because I could. Because I had a phone and a few dollars and a little bit of luck. Because sometimes, being in the right place at the right time means nothing if you don’t do something.

My coworkers asked why I was smiling the next day. I told them I’d had a good night. They didn’t ask for details. Night shift people know better. Some stories are private. Some wins are quiet.

I still play on vavada mobile. Small stakes. A few hands of blackjack on my breaks. I’ve lost more than I’ve won since that night. That’s fine. That’s how it works. But I always keep a little in my account. Not for me. For the next stranger. The next broken-down car. The next person who needs a hero at 3 AM.

People say gambling is selfish. Maybe it usually is. But that night, it wasn’t. That night, a slot machine and a blackjack table and a stupid roulette wheel turned into sixty dollars turned into a tow truck turned into a dad who made it to his daughter’s birthday.

I don’t know her name. I don’t know if she had a good party. I don’t know if her dad told her about the gas station cashier who stayed up late and played blackjack on his phone. Probably not. That’s fine.

Some heroism is anonymous. Some wins are never recorded. Some luck is meant to be shared.

I’m not a gambler. I’m a cashier who got lucky one night. But I’m also a person who decided to use that luck for something good. And that feels better than any jackpot. That feels like winning. Real winning. The kind that doesn’t show up on a balance screen.

The vavada mobile site is still on my phone. I open it sometimes. Not to play. To remember. The stranger. The coffee. The ten dollars that turned into sixty that turned into a miracle.

Best win of my life. And I didn’t keep a penny.
Post Reply