• What?
  • Who?
  • Contact Jonathan Jeter
  • Privacy Policy

Jonathan Jeter

Director of Application Development

  • Jonathan Jeter on Google+
  • Jonathan Jeter on Facebook
  • Follow Jonathan Jeter on Twitter
  • Jonathan Jeter on LinkedIn
  • Jonathan Jeter's rss feed
Home Web Development Front-End Development Front End Legos

Front End Legos

February 2, 2013 By Jonathan Jeter 2 Comments

by Shay Howe at HTML5 Texas Conference in Austin, TX (Deck)

There are a million ways to write HTML and CSS, and everyone has their own, but is there a right way? Our code needs to be well structured, written in an organized manner, and performance driven. Sharing code with others should be a joyful experience, not absolute terror.

In this session, Shay will cover some best practices and performance tips for writing the highest quality HTML and CSS possible. Writing code is the easy part, finding a practice and structure that works well across the board is the hard part. Shay will outline HTML and CSS conventions that can be applied to your everyday practice.

Front End Legos - Building Modular CSSCommon Problems

  • Websites have difficulty scaling
  • code becomes brittle
  • Files and code bases begin to swell

What’s Wrong

Best practices aren’t exactly best practices

  • avoid extra elements
  • avoid classes
  • leverage type selectors
  • leverage descendent selectors

We code so specifically (leveraging selectors) that we can’t make the changes we were trying to code for

Specificity?

  • Specificity determines which styles are applied

Maintainability

Code must be…

  1. organized
  2. modular
  3. performant

Organization

Approach

  • stop thinking about pages

Base

  • Core styles for entire site
    Normalize (reset), default elements, grid, variables

Components

  • User interface concepts & design patterns
    Alerts, buttons, forms, lists

Modules

  • Business logic
    Aside, Header, Footer

Your goal over time should be to not write css and just write HTML and see how the styles are automatically applied.

Looking at rdio site for modularity

Modularity

We put a lot of effort into our properties and values, but not so much on our selectors.

  • use a grid
  • separate presentation (or theme) from layout

code for reusable elements

Accommodate Content

  • remove the container element selectors
  • Use selectors instead of elements

Great ideas on using classes to really separate content from layout

Watch Specificity

  • be explicit
  • keep specificity low
  • Never use IDs or !important
  • avoid nested selectors (minimize)

measuring Specificity

Formula

count IDs, Classes/Pseudo-classes/attributes, Elements

High Specificity (bad)

Low Specificity (good)

Use Classes

  • write understandable class names
  • avoid unnecessary nesting
  • use same strength specificity

Methodologies

OOCSS

Object-Oriented CSS (Nicole Sullivan – oocss.org)

SMACSS

Scalable and Modular Architecture for CSS (Jonathan Snook – smacss.com)

Reuse Code

  • Do not duplicate code
  • remove old code
  • defer loading subsequent styles

Minimize Requests

  • combine lide files
  • use image sprites (use caution)
  • use data URIs (difficult to edit)

Compress & Cache Files

  • utilize gzip compression
  • losslessly compress images
  • cache common files

HTML5 Boilerplate includes compression and caching

Getting Started

  • Build a styleguide (Twitter Bootstrap, Zurb Foundation)
  • Review Methodologies (OOCSS, SMACSS)
  • Test your code (CSS Lint, Inspector, PageSpeed)

Here is a video of the talk.

Related articles
  • An Advanced Guide to HTML & CSS
  • Sneak Peek Into The Future: Selectors, Level 4 (CSS4) is here
  • Coding Q&A: CSS Performance, Debugging, Naming Conventions

Tell someone about this:

  • Email
  • Print
  • Twitter
  • LinkedIn
  • Facebook
  • More
  • Reddit
  • Pocket
  • Tumblr

Like this:

Like Loading...

Related

Filed Under: Front-End Development, Web Development Tagged With: bad Low Specificity, Base Core styles, Best Practices, Cache Files, Cascading Style Sheets, Class (computer programming), class names avoid unnecessary, code bases, common files, Components User interface, conference notes, container element selectors, CSS conventions, CSS Jonathan Snook, CSS Lint, CSS Nicole Sullivan, CSS Performance, CSS Sneak Peek, Data Formats, date content, default elements, design patterns Alerts, elements Accommodate Content, elements Great ideas, Elements High Specificity, entire site, entire site Normalize, extra elements, great ideas, grid separate presentation, highest quality HTML, HTML, HTML5 Texas Conference, Jonathan Snook, layout code, leverage descendent selectors, leverage type selectors, lists Modules Business, Maintainability Code, Markup Languages, modular performant Organization, modularity Modularity, nested selectors, Nicole Sullivan, old code, old code defer, oocss.org SMACSS Scalable, performance tips, reusable elements, right way, Shay Howe, smacss.com Reuse Code, Specificity determines, Specificity Formula count, specificity Methodologies OOCSS, Style Sheets, styles Minimize Requests, Technology Internet, Texas, Texas conference, Use data, User interface, Zurb Foundation

About Jonathan Jeter

Jonathan Jeter has been creating websites since 1997. He is currently Director of Technology Services and Digital Development at TracyLocke, a shopper marketing agency. You can follow him @mywebthoughts, on LinkedIn or connect on Google+.

Comments

  1. Umber code says

    April 10, 2013 at 7:47 am

    I am currently trying to create a workflow for myself that involves modularity. True modularity. This means (to me) that each module consists of it’s own html (or php), css and js. This module should be able to function on itself (when it is not part of a bigger whole) because one aspect that is never mentioned is that modules should be framework agnostic. It should not have to matter if I use the module in WordPress, Yii, Joomla, phpCake or whatever.
    There are 2 main problems I encounter.
    1) Since styles need to be modular by itself, (the module must be styled according to the project needs) it must be possible to override the included styles in the module. CSS cannot do such a thing (unless we use !important for every style) and while e.g. sass enables us to override variables, it does not allow us to do so with mixins or functions.
    2) How does one compound Javascript files in such a way that on-the-fly editing is still possible (in other words, no build-process should be required) since on-the-fly editing is one of the major advantages of webdevelopemnt (in my mind).
    I see an increasing amount of articles covering modular design, but they all seem too theoretical to me not aimed at true practical applications?

    Reply
    • Jonathan Jeter says

      July 15, 2013 at 4:26 pm

      Good questions. Those are a lot of requirements. I’ve had limited success in implementation and every framework seems to need a different solution. I think we’re still a ways from getting a true combination of boilerplate, css preprocessor and javascript framework that will work together in a way that modules can truly be independent and work within different systems.

      Thanks for posting your comment. I need to take another look and maybe it will result in another blog post.

      Reply

What do YOU think? Let me know...Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Stuff I Like to Talk About:

  • Business
  • Digital Imaging
  • Internet Marketing
    • Email Marketing
    • SEM / Paid Search
  • Life
  • Other Stuff
    • Health
    • Taekwondo (TKD)
  • Sports
    • Football
  • Technology
    • Augmented Reality
    • Awesome or Scary?
    • Marketing Technology
      • Data / Analytics
      • Omnichannel
    • Mobile
      • Android
    • Virtual Reality
  • User Interface / User Experience Design
  • Web Development
    • Browsers
    • CSS
    • Front-End Development
    • Google+ (Google Plus)
    • HTML5
    • JavaScript
    • jQuery
    • Mobile
    • MVC
    • Responsive Design
    • SEO
    • Social Media
    • UI/UX
    • WordPress

HTML

  • HTML Entities

JavaScript

  • MEAN.js

My Sites

  • Head Turning Media
  • Jonathan Jeter (Brand Yourself)
  • My Humor

Online Experts

  • Bryan Eisenberg
  • Danny Sullivan
  • Duane Forrester
  • Keith Brown
  • Louis Gray
  • Matt Cutts

UI / UX

  • Jared Spool
  • Paul Jeter
FreshBooks
Genesis Framework for WordPress Premise Landing Pages Made Easy

Most Popular

  • Verizon Wireless – My Favorite Mobile Provider
  • Exploring Standard Ad Unit Sizes: Google AdSense…
  • Intro to WebGL and Three.js – Front Porch…
  • Who?
  • People Data and the Future of Marketing –…
  • Exploring Standard Ad Unit Sizes: Google AdSense…
  • A Brief History of the Complete Redesign of Google…
  • Contact Jonathan Jeter
  • Privacy Policy
  • Looking for Instagram or Android fonts or logos and…

Copyright © 2025 Jonathan Jeter

 

Loading Comments...
 

    %d