Nicolas Gallagher

nicolasgallagher.com · Personal blog · on HN since 2010

Nicolas Gallagher is a front-end developer who writes about CSS techniques, HTML semantics, and creator of normalize.css.

What HN saysHN commenters cite his work on HTML semantics and file size, and his micro-clearfix hack, as examples of well-written front-end code.
50HN people shared it
29linked it in comments
34stories submitted
1.4Kstory points
3 years agolast shared
2010people per year2026

Most-shared posts

  1. 1
    About HTML semantics and front-end architecture
    14 people · 78 points · first shared 2012 · 8 comments on HN
  2. 2
  3. 3
    Demo: Pure CSS GUI icons, no images (experimental).
    5 people · 205 points · first shared 2010 · 65 comments on HN
  4. 4
    Pure CSS GUI icons (experimental)
    3 people · 131 points · first shared 2010 · 28 comments on HN
  5. 5
    CSS background image hacks
    3 people · 120 points · first shared 2011 · 8 comments on HN
  6. 6
    Pure CSS speech bubbles
    3 people · 2 points · first shared 2012 · discussion on HN
  7. 7
    CSS3 Social Sign-in Buttons
    2 people · 70 points · first shared 2011 · 11 comments on HN
  8. 8
    CSS: the cascade, specificity, and inheritance
    2 people · 6 points · first shared 2012 · discussion on HN
  9. 9
    Pure CSS speech bubbles – Nicolas Gallagher
    2 people · 4 points · first shared 2010 · discussion on HN
  10. 10
    Flexible CSS cover images
    2 people · 2 points · first shared 2014 · discussion on HN
  11. 11
    Responsive images using CSS3
    2 people · 2 points · first shared 2011 · discussion on HN
  12. 12
    A new micro clearfix hack [2011]
    2 people · 1 points · first shared 2012 · discussion on HN
  13. 13
    Brilliant use of CSS drop shadows
    1 people · 426 points · first shared 2011 · 60 comments on HN
  14. 14
    CSS3 Facebook Buttons
    1 people · 85 points · first shared 2012 · 5 comments on HN
  15. 15
    Another CSS image replacement technique
    1 people · 25 points · first shared 2012 · 2 comments on HN

What HN people wrote when they linked it

ZeroGravitas · 2017-01-11
An ecosystem of attractive looking templates, devs who know how to use it, various tools that integrate or output it, examples and tutorials to learn from, code samples to re-use etc.? There's also a justification for the type of classnames you're railing against here: http://nicolasgallagher.com/about-html-semantics-front-end-architectur… I believe Bootstrap adopts many of these ideas. So it's not just a mistake, but an intentional decision as part of a different paradigm. Feel free to suggest that it's not a useful way to build websites, but don't be fooled into thinking they've accidentally broken a rule they intended to follow.
ssorallen · 2014-02-21
Nicolas Gallagher addresses and deflects this point specifically with real numbers: http://nicolasgallagher.com/about-html-semantics-front-end-architectur… The link came from an earlier poster. Once you compress the HTML, the savings are insignificant compared to the likely 10s or 100s of kilobytes of images and JavaScript on a modern web page. Given how tiny the savings are, there are other places more worth your time to save bytes.
purephase · 2012-07-24
I find with Devise and Omniauth it works like magic. rbates has some excellent Railscasts on the process as well. I agree with the main thrust of the argument though. OAuth providers do not make it as easy as they should. The point about the buttons is spot on. I've had some good success with the buttons provided here: http://nicolasgallagher.com/lab/css3-social-signin-buttons/
Boldewyn · 2012-06-21
Yay! Someone finally invented the clearfix method! Or wait, hasn't someone else done that before? My personal favorite: http://nicolasgallagher.com/micro-clearfix-hack/
retlehs · 2011-04-02
Why should it demonstrate proper HTML? Because you're showing everyone how to do something. Sites like http://css-tricks.com/ and http://nicolasgallagher.com/ don't show you how to make things with incorrect code, they show you how to make things with beautiful, semantic code.
throwaway284534 · 2023-02-18
I do appreciate your transparency, though I disagree with the sentiment that I’m arguing from a position of bad faith. The Babel team has not shown a moment of interest in lowering their role in the JavaScript ecosystem to anything short of kingmakers. I think the facts are self-evident, but I can easily back up my claims by citing pretty much any document the team has ever produced. Have a gander at their GitHub README and what do we see?[1] - “Babel is a compiler for writing next generation JavaScript.” I suppose they left out “indefinitely” to avoid the obvious. Don’t forget, you’re here forever. - Over a dozen sponsor logos. An embarrassment of riches. - A literal audio recording of a song in praise of the project. The call is coming from inside the house, people! The Babel team has a well documented history of their priorities[2], emphasizing the need for a modular approach that has no exit strategy[3]. At best, we have a case of accidental entrenchment and long term dependence on Babel brewing as early as 2017![4] At worst, we have a group of aspiring Carmack-wannabes looking for their big break into the incestuous and lucrative class of technorati standards committees. Don’t believe me? It doesn’t take an inner-join on the TC39 roster and the Babel maintainers to see our own version of regulatory capture forming right before our eyes. Compare this infinite circus to the humble but popular Normalize.css, which has the express purpose to stop existing.[5] If the…
adamwathan · 2020-03-19
This approach is extremely seductive because on the surface it sounds so "pure" and "clean" but the reality is that on large projects it leads to some of the most horrific, hard to maintain CSS you'll ever see, no matter how hard you try to keep things in good shape. CSS is just inherently more difficult to maintain than HTML, and choosing a workflow that encourages editing CSS instead of HTML just makes things harder and harder over time. Choosing an approach where CSS is treated like a third-party dependency that is _consumed_ by your HTML ends up being much more practical, maintainable, and scalable because editing and maintaining HTML is _easy_ — every time you change a class on an HTML element your changes are local and predictable. Always thought this article by Nicolas Gallagher did the best job arguing this point: http://nicolasgallagher.com/about-html-semantics-front-end-architectur…
Raphmedia · 2019-04-08
It's a cool little snippet but it's nothing more than three run-of-the-mill CSS declarations. The maximum width is specified, a small padding is applied and the margins around the element are set to automatic so it centers itself horizontally. All the other styles applied on this pages are not part of the snippet. The weight of the titles, the spacing under the paragraphs, etc., are all specified on the page's CSS file but not described in the blogpost itself. [0] I was expecting something akin to normalize.css[1] which normalize the default styles of your page[2]. There are multiple very lightweight CSS "frameworks" that you should carry around instead of the snippet shown here. We are talking ~5KB. See https://github.com/troxler/awesome-css-frameworks#very-light for a great list. [0] https://jrl.ninja/etc/post.css [1] http://nicolasgallagher.com/about-normalize-css/ [2] Normalize CSS aims to make built-in browser styling consistent across browsers. Elements like H1-6 will appear bold, larger et cetera in a consistent way across browsers. You're then supposed to add only the difference in decoration your design needs.
jasim · 2017-04-10
The concept of 'semantic classnames', even if propagated by w3.org has caused as much grief as the concept of 'separation of concerns' between HTML & CSS fad. The reason we need semantics in HTML is to make the markup accessible for screen-readers, and no screenreader considers the class name of an element when reading it out. What we instead need are semantic tags like article, section etc. and aria tags like role. CSS classnames are purely for the developer's benefit. Not the user's. And as developers, forcing ourselves to find semantic meaning for every element we write leads us to component-oriented CSS like BEM. Which is a fine thing, but we can also use purely visual classes - like `bg-red bold border-solid` if it helps (and it does. check out tachyons.io) The class names of elements in Google's homepage for example reads like 'tsf-p', `oq`, `gsb` etc. I suspect these are machine generated. Same with Facebook. One of the best libraries to do this currently is styled-components (https://github.com/styled-components/styled-components). Consider reading http://nicolasgallagher.com/about-html-semantics-front-end-architectur… http://mrmrs.io/writing/2016/03/24/scalable-css/, and http://johnpolacek.com/2016/06/17/atomic-css-movement/ for reasoned perspectives.
lsdafjklsd · 2015-10-26
The no nesting thing is huge! We refactored a lot of CSS earlier this year and that was one of the biggest pain points. Coupling the structure of your template to your CSS makes changing things very painful. Nesting also creates ambiguous classes that have no obvious connection, consider the following: .my-component { .header { ... } } You would just see header floating around in the markup, unsure of where it's namespaced. Also I disagree that you shouldn't modularize your CSS. We now create a CSS file who's name corresponds with the class name. /styles /components my-component.css and in the markup <div class=".MyComponent-wrap"> <div class=".MyComponent-title"> ... </div> </div> With CSS like that you always know where a style is declared, and the order of the classes do not matter. More on the issue: http://nicolasgallagher.com/about-html-semantics-front-end-architectur…
WickyNilliams · 2013-09-11
Why are people hating on HTML semantics? I fear it is out of some fundamental misunderstanding of how semantics work on the web... First let me be clear that there are (at least) two types of semantics on the web, one for machines (bots and screen readers) and one for meat (humans!). In writing HTML, the goal is not to use every semantically-rich tag available and avoid everything else like the plague. Where you can convey extra semantic meaning, use the most appropriate tag available; where you cannot, use a div or a span or something else. Use of divs does not make your page less semantic - it is not deductive. However use of the correct semantic tags will make your page more semantic - it is additive! In writing CSS, the goal is not to avoid classes/IDs altogether to keep your HTML "clean". The machines care not if your HTML is rammed full of classes; though you will certainly care when it comes to maintaining your pristine HTML. When writing CSS the goal isn't even to strive for "semantic" class names. CSS classes convey no semantics, at least not to machines. CSS classes should be used to convey semantics to the meat bags reading the code - devs, interested users etc. Nothing else matters with CSS, write it how you like, in as maintainable a fashion as possible and forget semantics in that domain. Excellent article discussing the fallacies around semantics: http://nicolasgallagher.com/about-html-semantics-front-end-architectur…
emmanueloga_ · 2022-01-14
seems similar to normalize [1] 1: https://nicolasgallagher.com/about-normalize-css/
j4_james · 2016-10-17
I remember seeing something like this before too. This is the one I was thinking of. http://nicolasgallagher.com/pure-css-gui-icons/
mrzool · 2015-04-12
Non-semantic classes are totally fine: http://nicolasgallagher.com/about-html-semantics-front-end-architectur… - Content-layer semantics are already served by HTML elements and other attributes. - Class names impart little or no useful semantic information to machines or human visitors. - The primary purpose of a class name is to be a hook for CSS and JavaScript. - Class names should communicate useful information to developers.
chdir · 2015-02-14
Nice work. I'll add 2 more to the mix (bookmarked these while searching for pure CSS icons recently). To answer the title, yes I'd definitely use one of these http://nicolasgallagher.com/pure-css-gui-icons/demo/ http://saeedalipoor.github.io/icono/
jekrb · 2015-01-12
These are awesome. Reminds me of the set Nicholas Gallagher created a few years ago. http://nicolasgallagher.com/pure-css-gui-icons/demo/
ZoFreX · 2014-08-27
Counterpoint to "not practical": We have a dashboard at work that displays, amongst other things, the CI build status. For reasons I won't go into, we cannot change the HTML. We can change the CSS though, using Stylish. The "build failed" / "build succeeded" icons were incredibly non-obvious and developers weren't paying much attention to them. Now, through a series of seriously horrendous CSS hacks, they display as really nice flat design green checks and crosses. Given that this dashboard only ever displays in literally one browser, on one big screen, it was completely acceptable to use CSS hacks to achieve the look I wanted. It was sites such as this one that helped me figure out how to twist a single HTML element into what I needed. Particular shout-out to http://nicolasgallagher.com/pure-css-gui-icons/demo/
philipwalton · 2013-02-04
The double hyphen is actually part of a pretty common naming convention (BEM-style) for distinguishing between separate components, component modifiers, and component sub-objects. Examples: https://gist.github.com/1309546 http://nicolasgallagher.com/about-html-semantics-front-end-architectur… http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem… http://engineering.appfolio.com/2012/11/16/css-architecture
d4mi3n · 2012-12-10
Sure: making geometric shapes and masks. A varient of diagonal borders is currently used in http://nicolasgallagher.com/pure-css-speech-bubbles/demo/ The trick there is to use the CSS :after pseudo-element to get a triangular shape/mask, but it's a bit of a hack. Having diagonal CSS borders that were properly supported would make doing stuff like this much cleaner and easier to implement.
logical42 · 2012-09-05
http://nicolasgallagher.com/about-html-semantics-front-end-architectur… Sorta interesting argument against this sort of grid system.
espeed · 2012-08-15
For more on Normalize.css, see "About Normalize" (http://nicolasgallagher.com/about-normalize-css/), esp "Normalize vs Reset".
youngtaff · 2012-05-15
This is a very elegant proposal that needs work but has some merit and I'd like to see it built on http://nicolasgallagher.com/responsive-images-using-css3/ The current srcset proposal has terse syntax and just seems to be recreating media queries in another form. Surely we should adopt a media-queries based approach and fixing media-queries where they are broken.
necolas · 2012-05-10
I made a bunch of this kind (and more complex) speech bubbles a couple of years ago: http://nicolasgallagher.com/pure-css-speech-bubbles/demo/ This is a nice little tool to help automate the production of the code for simple ones.
jacobr · 2012-03-06
Neat trick. It's mentioned in the article, but if you don't care about IE6 or IE7, you should consider http://nicolasgallagher.com/css-image-replacement-with-pseudo-elements… It's a bit depressing that we're still fooling around with these different hacks though.
mike-cardwell · 2011-02-17
Ah, read: http://nicolasgallagher.com/css-drop-shadows-without-images/ "Known browser support: Firefox 3.5+, Chrome 5+, Safari 5+, Opera 10.6+"
SkyMarshal · 2010-06-30
Well icons and buttons can all be done in CSS3 now: http://nicolasgallagher.com/demo/pure-css-social-media-icons/ Photos obviously can't, so I guess that's a reason to keep photo editors around. But is that all? And yeah, I never liked mocking up sites in photo editors either.
achairapart · 2018-09-27
1. Think about this: You have to write or customize .profile-card for every project, with "m-5 p-5 text-gray-light bg-gray-darker border border-gray-light" you're writing 0 lines of CSS. Zero. All your CSS will be your utility framework (sizes around 5~15kb) and it will never increase in size. Now, tell me you never seen a two year project where CSS alone reached 2+Mb because at every edit someone added another class to the list... Also: When you gzip your HTML those repeated classes will compress pretty well. 2. Yes, you're right! Same specifity for the example in question. My point was more in general. Think @extend[0], nested selectors in SCSS. They look less scarier than "m-5 p-5 text-gray-light bg-gray-darker border border-gray-light" but they do not always do good. And I can tell you'll have no side effects: If you look at the HTML only, what ".profile-card" does? Does it add padding, typography, borders, transitions? How do you extend it? I can't tell. But I know for sure that "m-5" will add margin and margin only. "bg-gray-darker" will add background-color and background-color only. And so on. Every class does only one thing. They don't overlap. Once you memorize the simple naming convention you can't go wrong. 3. Why it looks harder to maintain? Do you all really get scared by a few, readable, classes? Also, classes are no meant to be semantic or content-dependent[1]. At the end, I don't want to defend to death this practice. Maybe it's a concept that is hard…
ahallock · 2013-05-12
I think you've read it right. Your HTML is more verbose, but you get used to it. I have elements like <h1 class="product__head"></h1> and it seems ugly and redundant (the h1 already indicates that the element is a heading!), but the advantage is that your CSS rules have a narrow scope (fewer collisions) and are easier to maintain. Further, your CSS is no longer coupled with your HTML. I would use .product__head in my stylesheet instead of .product h1 or h1.product__head. Then, if someone changes the h1 to h2, the stylesheet doesn't have to change. Essentially, you just have to treat your HTML class names as hooks into your CSS; that's their function. Your CSS rules should not be concerned with your HTML structure. I hope that helps. EDIT: This article, mentioned elsewhere in this thread, does a fine job explaining these concepts: http://nicolasgallagher.com/about-html-semantics-front-end-architectur…

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close