Skip to main content
117 votes
Accepted

Why are large amounts of magic numbers acceptable in CSS and SVGs?

Firstly, magic values are avoided in programming by using variables or constants. CSS does not support variables, so even if magic values were frowned on, you don't have much of a choice (except using ...
JacquesB's user avatar
  • 59.8k
78 votes

Why are large amounts of magic numbers acceptable in CSS and SVGs?

It's acceptable because these formats are not code, but data. If you were to remove all the "magic numbers," you would essentially duplicate every label, and end up with ridiculous looking files like:...
Karl Bielefeldt's user avatar
48 votes

Why does :nth-child() in CSS start from 1 instead of 0?

CSS uses ordinal numbering when identifying elements in an ordered collection. For example, :first-child matches the first child element of a parent, @page :first matches the first page, ::first-line ...
JacquesB's user avatar
  • 59.8k
25 votes

Why are large amounts of magic numbers acceptable in CSS and SVGs?

The prohibition on magic numbers is the primordial version of this design principle: Make decisions in one place. But these are not magic numbers. At least, not as far as any coding style guide I ...
candied_orange's user avatar
25 votes
Accepted

Are ems still relevant?

However, this effect will be negated if I define the font size in the body tag for example. body { font-size: 16px; } Because now my css is overriding the font size set by the browser. You are ...
Arseni Mourzenko's user avatar
20 votes
Accepted

Should minified CSS be stored in Git?

"It depends." For normal development tracking, no. For cloud and DevOps deployments, however, it's often convenient, or even required. Most of the time, @ptyx is correct. Indeed, his "no" could be ...
Jonathan Eunice's user avatar
19 votes

Should minified CSS be stored in Git?

No. Source control should only contain source. If it's generated from source, it doesn't belong there - and should be generated by your build process. The fundamental reason you don't want to source ...
ptyx's user avatar
  • 5,861
17 votes
Accepted

Why does Facebook obfuscate the names of CSS classes?

It's called minification. It makes the CSS files (and potentially Javascript files too) smaller, requiring less bandwidth to download. This can make a significant difference in performance, ...
John Wu's user avatar
  • 26.6k
17 votes
Accepted

How to namespace your CSS?

There are no namespaces in CSS. All you do in CSS ends up in global scope. This is by design. This leads to two problems: What happens to the apps using my library if, in the library, I introduce a ...
Arseni Mourzenko's user avatar
13 votes

What makes BEM better than using a nestable style sheet language like LESS?

Edit 2024 If you're reading this in 2024, we have multiple framework options. CSS in JS options such as Styled Components, Linaria, Angular components allow us to directly scope styles to individual ...
superluminary's user avatar
13 votes
Accepted

Are there any reasons not to ever use classes or ids anymore?

This seems like a very bad idea to me. defining css rules for classes and adding those classes to the html is a great way to make your css reusable. The way you're suggesting, with a complex selectors,...
alexanderbird's user avatar
13 votes
Accepted

Why is it bad to use inline styling in HTML for generic styles?

Looking at your updated question, Why is this <div> <textarea class="width90"></textarea> </div> .width90{ width:90%; } any better than this? <div> <...
Dan Pichelman's user avatar
13 votes

Are ems still relevant?

the point of ems is to define all measurements in your webpage, by the base font size This may be a misunderstanding of terms on my part, but to clarify: em is relative to "the current element's" ...
svidgen's user avatar
  • 14.7k
11 votes
Accepted

Why doesn't CSS allow single-line comments?

Backwards compatibility Introducing single-line comments to the CSS syntax could change the meaning of files which currently uses the token //. Browser vendors are very reluctant to introduce changes ...
JacquesB's user avatar
  • 59.8k
10 votes

Why are large amounts of magic numbers acceptable in CSS and SVGs?

Because CSS is not a programming language, instead, it is the configuration file that contains the variable data for your program. Currently CSS is so powerful that you can actually program in it, ...
Dorus's user avatar
  • 459
10 votes

Why does :nth-child() in CSS start from 1 instead of 0?

From the CSS Level 3 Selector Specification: 6.6.5.2. :nth-child() pseudo-class The :nth-child(an+b) pseudo-class notation represents an element that has an+b-1 siblings before it in the document ...
Adam Zuckerman's user avatar
9 votes

Will it be a wrong idea to have <style> in <body>?

(Since we are here at SE.SX, a more strategic approach may be a valuable augmentation to the usual technical considerations.) [preamble] The HTML5 spec is a continuously moving target, and they have ...
Sz.'s user avatar
  • 191
9 votes

Why does Facebook obfuscate the names of CSS classes?

Another likely answer is that they use this to subvert adblockers. These usually select elements for removal based on their css attributes, i.e.: class="post promoted". Obfuscating the css names makes ...
Busti's user avatar
  • 191
8 votes

Why is it bad to use inline styling in HTML for generic styles?

In layman's terms: Because when you have a lot of pages with a lot of inline styling, and some user askes for cosmetics change, the you will have to make a lot of changes in a lot of places, and ...
Tulains Córdova's user avatar
8 votes

Why doesn't CSS allow single-line comments?

Supporting yet another syntax element isn't that easy: there are plenty of tools which should be able to handle yet additional comment style. Actually, I wouldn't be surprised to see that most ...
Arseni Mourzenko's user avatar
7 votes
Accepted

Is there a rule of thumb when it comes to the "name" attribute?

Name is a CDATA type so the following applies: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), ...
Rob's user avatar
  • 286
6 votes

What are CSS modules? Are they a library, or a spec, or what?

CSS modules rely on the native CSS and JavaScript processing capability of web browsers. Therefore you need not install anything new; a web site might use them and you could never notice. As the ...
Kilian Foth's user avatar
6 votes
Accepted

How to white label my website in php

Its been a few years now, but the last PHP system I developed did something like that. We offered custom domain names, rather than directories, but the principal is the same. It was a template ...
GrandmasterB's user avatar
  • 39.4k
6 votes

Why don't web browsers know the physical dimensions of a display?

In general, a computer has no idea of the physical size of the monitor you have plugged in to it. That may be different for smartphones or tablets, of course. But some tablets have HDMI outputs. It's ...
Simon B's user avatar
  • 9,633
6 votes
Accepted

Could there be a <flex> tag?

This question is wildly in need of focus, but most of the questions have an easy answer. Who is in charge of this? The W3C. Is there a place to submit proposals? Yes. See the link above. The first ...
Greg Burghardt's user avatar
5 votes

Where to put css media queries in a CSS file?

I found this source helpful in answering this question. CSS Declaration Order. When reading this link it talks about the order in which CSS code is placed. "Related property declarations should be ...
RajoYak's user avatar
  • 51
5 votes

Why are large amounts of magic numbers acceptable in CSS and SVGs?

Why is it [a bunch of seemingly random hard-coded values] OK for CSS/SVG? It isn't OK. It's possible to write and maintain plain ".css" files, but eventually random hard-coded values will become a ...
Jackson Ray Hamilton's user avatar
5 votes

Is CSS inspired from C?

Yes. If you check the original proposal: https://www.w3.org/People/howcome/p/cascade.html you can see the following quote The C-style syntax of the first statement reads: If the document is ...
Ewan's user avatar
  • 77k
5 votes
Accepted

Advantages and disadvantages of including JS/CSS inside the HTML?

The reason why js and css will be seperated is for bundling and minification purposes. When you write them inside a HTML file, then the file size increases and takes time to load, which will degrade ...
T.kowshik Yedida's user avatar
4 votes

Client wants browser's back button to work on a website doing AJAX calls

My client wants the browser's back button to work, but since you're not moving to a different page or anything, I don't think that's actually possible, is it? No, it certainly is possible. When ...
Winston Ewert's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible