NameSilo

<Div> tags

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch

sin

VIP Member
Impact
130
Just wondering why people use so many div tags in their websites, does it help loadtime or something?
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
They load faster, yeah :)

Its easier to be more creative as well than with tables.
 
0
Close
Well you can do anything with a div, instead of using tables which are deathly evil, its a block based element I believe.

You don't need all the <tr> and <td> markup with a div, you use css to change its property's which in turn you can change any time, resulting in a change of all your pages etc...

Here is a good explanation of what the div tag actually is: http://webdesign.about.com/od/htmltags/p/aadivtag.htm
 
1
Close
Yeah I've been saving some popular websties taht I go to, to look at how their layouts were made and they all use mostly DIV tags. I used to use tables a lot ;(.
I'm having some trouble with a table right now. So I'm going to try all that div stuff right away ;).

Thanks
 
0
Close
Everyone keeps saying div tags load faster than tables... I just want to clarify, and correct me if I'm wrong, it's not that div tags just load faster than tables, it's the fact that less characters typed into an HTML document when using div tags... take for example a simple box with a border and the words Hello World!.

HTML:
<div class="greeting">Hello World!</div>

And it's table counterpart

HTML:
<table><tr><td class="greeting">Hello World!</td></tr></table>

And that's just bare bones table code. You would/could also specify cellpadding, cellspacing, borders, etc. right in the table tag. Now imagine a complex design using a table layout. Most table layouts require spacer images in order for designs to be placed in the appropriate areas on the screen. You can potentially cut the size of an HTML document in half using div tags over table tags. In the short term it may not seem like much, but if you're running a site that gets 1,000 unique visitors a day you'll notice a bandwidth savings in the long term.
 
0
Close
WOW, this is really cool. Just started using them, I never knew about this stuff ;) thanks
EDIT;
I'm really glad I posted this, this is so much easier then tables omg!
 
Last edited:
0
Close
I agree, it took me only 10 minutes to understand CSS and just two websites to master it. I'm glad more and more big websites are taking up tableless design :)
 
0
Close
Hmm, I have another question, If I have a table that has 2 rows and 8 colums
(the top part only has one colum b/c I added colspan="8" in the first <td>)
so it looks like this
|-------------------------|
| 1|2 |3 |4 |5 |6 | 7| 8 |
|-------------------------|
By adding in 8 <div> tags in the colums that just makes it load slower right,? Because it takes up more code.
I have the table because I want 8 colums with certain width's
Is there a way to save loadtime by using <div> instead of the table for a situation like this?
 
0
Close
Sure. Why not just use a <div> for each cell?

If you have tabular data however, you should use tables (since that's what it's for).
 
0
Close
I thought of that, I think that I would have to make about 3 or 4 different styles for tables then, tablestyle1 width=55 style2=65 ect...
Coloums just seemed so much easier, but Ill try that I guess.
 
0
Close
CreedFeed said:
Everyone keeps saying div tags load faster than tables... I just want to clarify, and correct me if I'm wrong, it's not that div tags just load faster than tables, it's the fact that less characters typed into an HTML document when using div tags... take for example a simple box with a border and the words Hello World!.

HTML:
<div class="greeting">Hello World!</div>

And it's table counterpart

HTML:
<table><tr><td class="greeting">Hello World!</td></tr></table>

And that's just bare bones table code. You would/could also specify cellpadding, cellspacing, borders, etc. right in the table tag. Now imagine a complex design using a table layout. Most table layouts require spacer images in order for designs to be placed in the appropriate areas on the screen. You can potentially cut the size of an HTML document in half using div tags over table tags. In the short term it may not seem like much, but if you're running a site that gets 1,000 unique visitors a day you'll notice a bandwidth savings in the long term.

I've used both and they both have definite pros and cons.
If somebody is having issues with tables, they may have similar issues with DIV tags. Tables are great because they force you to use a definite hierarchial structure (table, colsspan, rowspan, table nested within table, percentage of size etc.) but this too can be applied to DIV tags. I like tables because it fits in with the theoretical/practical topology of database data (again, that point too can be applied to DIV but its not as inherent)

As for cellpadding, spacing, borders and the like (or if you are on the current standard: border, border-spacing, and border-collapse) - there is little difference here between table & layout. You can save time & some space by using CSS for either/both tables and div, that should not be your reason for switching! Using CSS to define/encapsulate UI is also great for organization & essential for quick maintenance and/or when working in team (can't stand it when one developer puts attribute in CSS and the other inline, it's impossible to troubleshoot & maintain)

As for saving bandwidth or for 'speeding up load-time', that's a REALLY HARD SELL as your average HTML file is tiny, probably a fraction of the graphics displayed on the simplest site (i.e. so you take your html file from 9k to 8k, but your graphics are 35k per page)... It's a myth that spread around the 'net like fire and I don't get it: tables account for 5 to 10% of an html file so you are looking at a small fraction of the issue (graphics take up more space, they take longer to download, and longer to render onto the screen). As for .CSS, though it saves time in coding, maintenance and is good for organization I would not consider it a means of 'increasing speed' signifigantly as users browser is still quering it per html file.

I'm willing to be proven wrong here. Heck, I'm always looking for reason to learn something new... I have done some simple research on the topic and didn't find anything signifigant. You can also look at http://www.decloak.com/Dev/CSSTables/CSS_Tables_02.aspx for more in depth info...

One place I use Divs and NOT Tables is for 'floating' selections that need to be quickly hidden/shown, as in http://eeleaders.com/webmaster/, checkout the first page at that page and put cursor on the red tags.

Just my two and a half cents.

Not looking for a fight or flame war (why I have to say that is beyond me... These threads always end up getting catty... I don't own stock nor have any interest in the furtherance of neither divs nor tables... To each their own)
 
0
Close
thanks engineer for your reply, I think that a few K of size in your file could make a big difference to slow connection users. Maybe a small difference but some of them will leave the site if it takes too long to load, making the index file as Small as possible is important to me :)

that last link you mentioned for floating <div>s is really cool, never seen that used before.. Not like that atleast.
 
0
Close
rocca said:
Hmm, I have another question, If I have a table that has 2 rows and 8 colums
(the top part only has one colum b/c I added colspan="8" in the first <td>)
so it looks like this
|-------------------------|
| 1|2 |3 |4 |5 |6 | 7| 8 |
|-------------------------|
By adding in 8 <div> tags in the colums that just makes it load slower right,? Because it takes up more code.
I have the table because I want 8 colums with certain width's
Is there a way to save loadtime by using <div> instead of the table for a situation like this?

You can use a list...<ul> and <li>, I forgot the style, but you can just style them horizontally, and it makes less code, and more 'semantically correct' markup ( or whatever).

Just because divs are good and can do wonderful things, don't cram 9000 into your pages...other tags are there for a reason :P
 
0
Close
Yep, the floating divs is really cool. That's a site that I made (graphics and all, except the client is changing the content/text a bit) and is in-line with my newer thoughts regarding web design/development. I used to be a big fan of JavaScript/DHMTL and then Flash, or just putting as much 'stuff' into a site as possible (like those Flash templates you see people hocking these days, were everything is moving, shining, you have the cursor customized, you have music, the toaster in the background pops via bluetooth, your phone rings and blue flames emanate out of your computers fan port).

Then I realized that as a programmer/developer, those types of sites are fun and educational to create but are really a Marketing mistake. At the end of the day you look at the 'success stories' on the Internet, beit Ebay, Amazon or Friendster and the one thing they all have in common is that they are bare-bones simple (make the wheel better, but don't reinvent it). That's why I try to go for simpler effects these days. My choice would be to use the effect alittle differently but alas, hopefully a project will come along for it soon. I recall that Divs (and various other objects) were notoriously finicky when trying to achieve a look that translated well among all the browsers but to my surprise, IE, Fireworks etc. handled the effect on that page very well (thanks to (I forgot name) folks on NamePros who let me know it was rendering wrong on Fireworks previously!)

As for saving a few K. Again, it's all relative. I don't see the use in saving 1K if you have 50K of graphics. It's not a matter of the space/bandwidth saved so much as it is a comparative analysis, as in: if I'm waiting 1 minute for a page to load, 1-5 seconds off isn't going to make such a big deal. The biggest issue I see among (especially newer) designers is lack of graphic optimization for Internet (you also see alot of this on Ebay, where people link to these metre by metre pictures shown as a 400 x 400 pixel pic (the 1m by 1m file is still downloaded!).

Ben

rocca said:
thanks engineer for your reply, I think that a few K of size in your file could make a big difference to slow connection users. Maybe a small difference but some of them will leave the site if it takes too long to load, making the index file as Small as possible is important to me :)

that last link you mentioned for floating <div>s is really cool, never seen that used before.. Not like that atleast.
 
0
Close
The moral of the story is... there's hardly anything you can't do with CSS right now. In fact, you should stop coding a website by making divs that look like tables, but rather make each content box or area its own element.
 
0
Close
JYM said:
The moral of the story is... there's hardly anything you can't do with CSS right now. In fact, you should stop coding a website by making divs that look like tables, but rather make each content box or area its own element.

True, but rocca you should learn about floats as well, so you can position two divs beside each other, learn about clearing divs as well.

Anyways good luck rocca.
 
0
Close
I still prefer to use tables because I find them far easier to structure pages with. In the end as it has been said, the pathetically flimsy talk about faster pages is quite silly. If you're more comfortable with tables, there's nothing stopping you using them.

They're still stylable using CSS so there's hardly an argument against them.
 
0
Close
If you look at the space savings in filesize in a larger picture the savings adds up. Like I said in my initial post, say you have a very complex design with tons of nested tables. Using DIVs you can potentially save a couple of K in page size. For example, let's use 2K. Now lets say you have 1,000,000 unique visitors a month. That's 2,000,000K in bandwidth saved. Sure your site may not get that many visitors or you may think you'll never get that popular of a site, but that doesn't mean you shouldn't shoot for the best optimized code you can have. If you work on optimization in the beginning you won't have to worry about it later.

And comparing HTML document size to image sizes on the page really doesn't work because most modern browsers will cache images. I can hit reload on your index page 20 times and I should really only grab your images once unless it's a dynamic image, whereas your index HTML page is called 20 times. Sure you can have your browser not cache images, but in general I think most people browsing the internet leave their browser settings at the default, which I'm pretty sure IE is set to cache.
 
0
Close
Well, with a small-medium sized website, the amount of bandwidth saved won't be very noticeable, but it's not about the bandwidth. It's about separating content from design, and making it more accessible to those with disabilities or screenreaders. That is the whole point of CSS. Of course, if you're familiar with tables you should continue to use them... but you should understand that sooner or later you will have to switch to something better as the Internet progresses.
 
0
Close
CreedFeed said:
If you look at the space savings in filesize in a larger picture the savings adds up. Like I said in my initial post, say you have a very complex design with tons of nested tables. Using DIVs you can potentially save a couple of K in page size. For example, let's use 2K. Now lets say you have 1,000,000 unique visitors a month. That's 2,000,000K in bandwidth saved. Sure your site may not get that many visitors or you may think you'll never get that popular of a site, but that doesn't mean you shouldn't shoot for the best optimized code you can have. If you work on optimization in the beginning you won't have to worry about it later.

And comparing HTML document size to image sizes on the page really doesn't work because most modern browsers will cache images. I can hit reload on your index page 20 times and I should really only grab your images once unless it's a dynamic image, whereas your index HTML page is called 20 times. Sure you can have your browser not cache images, but in general I think most people browsing the internet leave their browser settings at the default, which I'm pretty sure IE is set to cache.

As for caching, it's a moot point as all parts of a page can be/are cached, including pics, markup & all (as anyone who makes alot of changes etc. to a page will attest to). Its also a broad generalization regarding graphics as you're example would most likely apply to sites one visits often (daily) and/or those folks who don't clean out temp & Internet cache regularly.

As for Div and speed...
I don't know how this DIV tag leading to faster, more efficient code rumour got started. You see it everywhere but it's so insignifigant (when its true) as to be totally irrelevant (it's 5% of a page AT MOST).
Remember, you are still putting style information in the CSS, so its not gone, just somewhere else. As for saving 2k (2000 characters?), even that seems a huge overstatement - what are we talking about here, <td><tr> tags?! With DIV you usually require more explicit size statements - with tables I can set the size of the widest cell per column and I don't need to do it for the rest. BTW: When you are working with complex layout of a large size, you are looking at some tricky nesting and etc., similar to what you'd see with tables.

If one wants to discuss putting HTML files on a diet they should:
1. Rewrite, by hand (manually) code produced by WYSIWYG editors which are still very inefficient and repetitive
2. Encapsulate Layout (Html) & Interface/Colors etc. (CSS), use inheritance in CSS, never repeat anything (esp. style attributes) more than once (again, the time you save in loading/bandwidth is NOT worth the extra time other developers will have to spend maintaining your strict anorexic code)
3. Eliminate unecessary tags and attributes (like autogenerated ID's for tables & other UI objects not being referenced by Server/Client side code and don't really have a purpose or use)

4. RUN A WHITE-SPACE ELIMINATION MACRO: I like to do this sometimes just to make my code harder to read by those folks who like to use VIEW SOURCE. It basically takes all the double-spacebar, tabs and new-line characters out of markup and puts all your html on one (very long) line. The Browser reads it the same but that really does save space (think about every line of code having a Line Feed/Carriage Return, you are eliminating them!)

JYM said:
.... it's not about the bandwidth. It's about separating content from design, and making it more accessible to those with disabilities or screenreaders. That is the whole point of CSS.

Amen... That's the key. And whether one uses Tables or Div tags as the base/skeleton for layout they should use CSS wherever possible. It makes for better organized and maintainable code, code accessible on multiple platforms (screenreaders and increasingly important: mobile platforms... Yes, you can have conditional CSS based on platform), and amazingly maleable UI.
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

New: watch any domain
You can now watch domains on NamePros. We check each one and notify you when something changes. Search for a domain and press Watch on...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back