Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Tables or CSS?

Hey Everyone There are a couple of websites that my friends what me to update and I noticed that all of them used tables for the layout. Is it better to use tables or CSS? What is your opinion?

4 Answers

Tables are great if the data within them is quantitative, but whole sites shouldn't be built that way. CSS is not only a better option but I'd go as far as to say it should be the only option when considering tables/CSS for layouts. If they've used tables in an attempt to line everything up nicely, building on a grid or using flex boxes are a better way to go.

Spot on Laura!

Tables were more popular back...I don't know when, but that was before CSS had all of it's cool features.

So your basically going to want to stay away from tables unless you have tabular data like the "Plans and Pricing" page on Treehouse.

Try to use CSS almost ALL the time.

Short answer: Reiterating what's been said, style rules for layouts. Tables are for data.

Long answer:

  1. Markup for content, style for presentation. Table tags are markup and should represent tabular content, using them for layout lends itself to bloated bad markup.

  2. Tables are very rigid, which is why it seems like a good idea to use them for layout. Up until the point you need to adjust the look of something, at which point you might as well rip the whole table apart and redo the page from scratch.

  3. Tables as layout can give your page a perceived slowness. A table element isn't rendered on screen until ALL of the element is loaded. Imagine you have a page who's height is 100 times the height of the clients monitor, and takes about 5 seconds to fully load. With a table layout wrapping the entire page, nothing will be rendered until the page fully loads at the end of the 5 seconds. With a style based layout the elements will be rendered as they are loaded, which allows the client to immediately start consuming the website as opposed to waiting 5 seconds. The client doesn't care how long it takes for the page to load, they care how long it takes for the page to be usable.

We had a re branding of the public website at my company last summer, and as a result the management wanted our legacy in house web apps to adopt the styling. The large majority of the apps were built using table layouts for EVERYTHING. I'm not kidding when I say that I spent days deleting tr and td tags and replacing them with divs, paragraphs, and even simple breaks. Average page sizes dropped 25%+ just by getting rid of all of the table tags wrapping everything in sight. I'd say it was horrible, but it was actually pretty fun deleting thousands of lines of code each day and still being able to deploy a working product at the end of the shift.

Thanks guys, I assumed that CSS was better for layout but I was a little unsure after seeing all of these new sites being done with tables. Thanks for the clarification.