Start learning with our library of video tutorials taught by experts. Get started

CSS: Visual Optimization

Indenting your code for readability


From:

CSS: Visual Optimization

with Justin Seeley

Video: Indenting your code for readability

When it comes to readability one of the most important things you can do in terms of CSS code is to indent certain areas of your code to add a little bit of distinguishing characteristics to that area of the code. When we talk about CSS rules, what we need to understand is that there's some sort of an unwritten rule when it comes to writing these and one I try to follow. If there's only one rule in you CSS declaration, you keep that on one single line. However, if you have multiple rules, you want to put that on multiple lines, and you also want to make sure that you indent the properties that you're working on.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
CSS: Visual Optimization
1h 11m Beginner Feb 12, 2013

Viewers: in countries Watching now:

Take a tour of a workflow that optimizes CSS code for easier navigation, organization, and readability. In this course, author Justin Seeley covers best practices for writing CSS in an easy-to-read format, commenting code, developing a table of contents, and adopting other methods that help produce "cleaner" code. The course also contains tips for speeding up development with some online tools and simplification techniques.

Topics include:
  • Exploring good versus bad style sheets
  • Creating section headings
  • Indenting code for enhanced readability
  • Creating single- and multi-line comments
  • Avoiding unnecessary tags and classes
  • Creating master color and typography guides
  • Simplifying comments
Subjects:
Web Web Graphics Web Development
Software:
CSS
Author:
Justin Seeley

Indenting your code for readability

When it comes to readability one of the most important things you can do in terms of CSS code is to indent certain areas of your code to add a little bit of distinguishing characteristics to that area of the code. When we talk about CSS rules, what we need to understand is that there's some sort of an unwritten rule when it comes to writing these and one I try to follow. If there's only one rule in you CSS declaration, you keep that on one single line. However, if you have multiple rules, you want to put that on multiple lines, and you also want to make sure that you indent the properties that you're working on.

So let's take a look at how that works right now. So I'm just going to go here underneath Universal Styles, and I'm going to start off with a new declaration here. I'm just going to type out just a fictitious classname. So I'll just type out .classname. Let's assume that this one is going to be just a one single line kind of thing. So I'm just going to do open curly braces there and a close curly brace and in-between those we're going type out border, and we are going to set it to 0 and semicolon like that. Since there is only one rule here, I'm going to keep that right there on one line.

However, let's say that I had another classname, .classname2, and we'll do open curly braces here. If I had more than one set of rules that were going to be applied here, I would just create a new line, and I would make sure that the second line is indented. In most modern code editors like Coda and others, they will automatically indent this second line for you. If they do not just press the Tab key over, and you will be able to Tab over like this. So I'll just type out something like Background, and we'll make that white and then border set to 0.

Then let's just say the color was something like that, and we have float left, margin 0, and let's do padding 0. So there's an example of how that would work. So in this case we have classname with only one rule so that gets put on one line with no indent right there, but in this case look how much easier to read this is right here. Everything is nice and concise. It is in order, and I actually put all of the different properties that I was working on, I put those in order as well as alphabetically.

So B for background, B for border, C for color, F for float, et cetera. I try to follow these unwritten rules to make my code a little bit more readable to other people, but also making sure that I use the indentation for these, because making that indent just lets me know, here is the start of this class, and it doesn't stop until the outdent happens towards the end. Everything that's indented now belongs to that class and everything that's not indented does not. This is a great way to help you distinguish between blocks and declarations of CSS and also a great way to help keep yourself organized as you continue to create your CSS documents.

There are currently no FAQs about CSS: Visual Optimization.

Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS: Visual Optimization.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked