2 replies [Last post]
Ne0nx3r0
Offline
newbie
Last seen: 11 years 5 weeks ago
Timezone: GMT-5
Joined: 2009-08-07
Posts: 8
Points: 7

I've wondered this for a while but haven't ever gotten a clear answer... What are the actual benefits of using the style tag as opposed to the style attribute for fire and forget css'ing?

I mean there are those occasional times where you're writing a dynamic page, and you want to highlight one specific

  • or , and it's easier to keep the code with the dynamic page since that's where your maintenance will be.
  • ...however...

    My assumption has always been that there's a possible rendering benefit if the browser already has the style loaded into memory (even if it's only being used once), but are there any specific benefits?

    Chris..S
    Chris..S's picture
    Offline
    Moderator
    Last seen: 9 years 1 day ago
    Timezone: GMT+1
    Joined: 2005-02-22
    Posts: 6078
    Points: 173

    If you're only affecting

    If you're only affecting one element in one page on the site, its not really going to matter where you put the style.

    I think you're wrong in assuming its easier to keep the code with the dynamic page for maintenance reasons. All your dynamic page should say is highlight this element (ie. put a class or id on the element). How the highlighting is handled should be placed with all the other page appearance information.

    Now you can maintain your site appearance all in one place without having to trawl through individual pages to change highlighting now that you've decided to update your site appearance. If you decide to remove the highlighting from that element you only need to stop the dynamic page putting the class/id on the element. Plus if you later decide to highlight something else on another page in the same manner, all you're adding is the class/id not all the styles.

    Ne0nx3r0
    Offline
    newbie
    Last seen: 11 years 5 weeks ago
    Timezone: GMT-5
    Joined: 2009-08-07
    Posts: 8
    Points: 7

    Thanks for the info! Maybe

    Thanks for the info! Maybe it's micro-coding, but I had never gotten a clear answer on how pages are rendered concerning style sheets.

    Chris..S wrote:

    I think you're wrong in assuming its easier to keep the code with the dynamic page for maintenance reasons. All your dynamic page should say is highlight this element (ie. put a class or id on the element). How the highlighting is handled should be placed with all the other page appearance information.

    I'm not assuming ; ) I figured there would be some grief about that, and I agree 90% of the time. I just find there are occasions when it can be more efficient to break traditions rather than keep them simply for the purpose of standards.

    For example, the page I was working on when this occurred to me was to be a placeholder piece for something else; in which case it's much easier to keep everything bottled within it so I could simply replace the content entirely when I'm ready, without having to remember what JavaScript file or style sheets I updated while I was making it. (and their subsequent cache issues)

    Most times I would agree though, keeping your interface away from your logic is a better path; but I don't believe in absolutes.