improve your front-end skills/setting standards

published on:
February 18, 2010 / 12:38
comments

Front-end development has come a long way ever since we've switched from tables to divs. In 10 years time our job shifted from after hours tweaking to becoming truly professional occupation. Still, when taking a moment to look around there is still lots of room for improvement. A little too much maybe, so here are some important pointers that will help you to become better at what you do.

1. learn about semantics

And by that, I mean truly learn about semantics. Not just the simple meaning of the available html tags, but also the reasons why we aim to write semantic code. This might sound very simple, but take one of your websites and take a good look at the class names you defined. Did you give them simple names or complex computer-like descriptions. Did you make sure you applied them consistently across all the pages. Not to copy css or javascript functionality, but because the elements are essentially the same.

/* bad */ .productList li /* good */ .productList .product

If you have blog posts, products, events or whatever other returning content type on your site, did you make sure that every content type, no matter what its context, received the same class name? .productList li doesn't cut it. A program doesn't make the assumption that productList is a concatenation of two words, making the list items "products". A program sees two different class names and leaves it at that, unless specifically programmed.

You once read that it's smarter to define a base class to an ul rather than place a class on each li? Sure, I've read that too. It's not necessarily wrong, but we're talking semantics here, not styling. So take a moment to consider how you handle semantic value in your documents. Are you really thinking about semantic value, or are you just worried about how to get your css in there?

2. learn about structure

html is more than semantics alone, it's also about structure. Tags like header, section and footer are there not to give specific semantic meaning to elements, but to group elements and to express relations between them. They are the foundation of your document.

Don't write html as a means to style your site or to add certain functionality. Wrap elements that belong together not because they are visually grouped, but because they belong together. If might not be useful now, but once the code is implemented in whatever cms you will notice that these elements give you a more flexible html structure.

Concepts like iterative design and scrum allow for quicker and smaller updates. Make sure that the code you write is somehow resistant to these little changes, or even complete redesigns. If you have to ask a code change for each question asked, you'll end up looking like an amateur.

3. keep your css clean

Sure, you've read this a hundred times already, but do you actually make sure that your css file is as clean as can be. Did you define general sections like grids, navigation, simple content, components, forms etc to structure your css? Did you group all css rules for each component, starting from the root tag, gradually going deeper into the component. Did you separate different components with a little title in a css comment? Made sure that your whitespace between rules and sections make any sense?

I see lots of css files pass by on a daily basis that do none of these things. The idea of keeping a clean css file might make a lot of sense to you right now, but once you start styling, it's a lot harder to actually achieve it. Take a half day off and make yourself a template for your css files. Define which sections return in each project and stick to them. Keep all the css of a single component nicely grouped and make sure that you comment where necessary.

When phase 2 of your project starts, you will thank yourself. Other people working on your code will do the same.

4. think, evaluate, improve

Usually projects are running on a tight schedule. This means you'll have to make choices during development that aren't as well-considered as they should be. This is not a bad thing, just make sure to take the time afterwards to think them over. Have a good idea, write it down and implement it in your next project. If it doesn't work out, just drop it and try something new.

Becoming a good front-end developer takes time and practice. Just make sure that you learn from your mistakes. Some parts are harder than others, but if you keep looking at a certain problem from different angles you will end up with a solution that's at least satisfactory. And if you're really stuck, ask others to give their opinion. There's a world of front-end people out there blogging about their job every single day. Most of them are very willing to help you out.

5. don't believe the hype

If you want to be good, inform yourself. Doesn't matter whether it's books, blogs, colleagues or courses, just make sure that you are following whatever is going on in our tiny world of front-end development. Just don't believe all the hypes. Many bloggers use their articles as self-justification for their own methods. No matter how many times you've read it these last couple of weeks, don't believe that css3 is ready for use. Don't simply believe in graceful degradation.

Read and ask all you want, but be sure to make a critical evaluation of what is being told to you. It's all about agreeing, not about believing. Front-end development is a pretty specific field dealing with a billion different people, using a billion different setups. Make sure that you give them an experience worth having, even if they are using crappy hardware or software. Things might look good on your screen, but if they suck on someone else's, you've lost your credit.

Using the latest technologies is fine, as long as you know where their limits lie, what the impact is on future development and how they leave older setups. People are right when they say that a single person will not compare your site in different browsers, but be sure that he will compare it to other sites. And he might be wondering why yours is so square and using solid color drop shadows. He'll probably think your site is a little sloppy compared to all those others. Is that really what you want?

conclusion

Nothing new you say? True enough, but the fact is that these pointers are still being neglected to the point where many professional companies are coming off as truly amateurish. Like most things that appear simple, mastering them can be a real pain. So make sure that each new project you tackle adds something to your skills. Read, try and think and rethink if it's not helping you, that's all there is to it.

Comments

Mathias Bynens

comment number
date
February 18, 2010 13:37

Similar to #3, "keep your CSS clean", one could also keep his JavaScript code clean, e.g. use document.documentElement.id = ''; instead of document.getElementsByTagName("html")[0].id = ""; ;)

Niels Matthijs

comment number
date
February 18, 2010 13:49

Thanks for the heads up, it's a shame my JavaScript skills are still very much below par ;)

Dan

comment number
date
March 10, 2010 12:20

In regards to #1:

While that example is indeed faster in Gecko browsers, the class attribute holds no semantics per definition. Only elements do. It makes them easier to read, if you use some sense while making up class names, of course.

I think using as few classes and ids keeps your HTML and CSS more tidy than anything. I prefer to use the cascade and more explicit CSS rules.

Niels Matthijs

comment number
date
March 10, 2010 15:33

I consider it accepted practice to use ids and classes to give extra semantic meaning to your html code. Not universal meaning, but meaning within the confines of your page (or site). It's the microformats idea without the actual microformats.

If you depend to much on cascade or structure for css, it makes your css code rigid and difficult to port. Not a good thing imo.

Dan

comment number
date
March 10, 2010 15:55

Somehow I knew you would bring the microformats argument. ;) Like I said, if the classes have some meaning it's easier for you, as a developer, to read - no doubt about it. But I'm not aware of a screen reader that makes any sense of class attributes. So I see no real semantics there.

I have to disagree on the portability. Think of it the other way: if you don't rely on class or id attributes, all you need to change is the css. Otherwise you may have to edit the HTML, too, which makes even less portability IMHO. I kinda blame CSSZenGarden for that kind of coding style. ;)

Niels Matthijs

comment number
date
March 10, 2010 23:21

But I'm not aware of a screen reader that makes any sense of class attributes.

Indeed, a screen reader can't make sense of it. You and any other custom made program could though. And in good time, search engines could also filter on commonly used classes like "product, review, article, news, event, ...". By no means fool-proof, but definitely a good step forward.

if you don't rely on class or id attributes, all you need to change is the css

Sure, but sometimes the html needs changing rather than the css, and in those cases it's silly if you have to adapt the css too.

I'm not sure if we're on the same wavelength here though, but I've seen people style on very specific structures like .content>div+div rather than .content .main ... this is all very well as long as the structure remains the same, but when it changes (another div is added in between or you're porting from html4 to html5 for example) your css becomes worthless.

I prefer styling a particular component based on a class. With that I can place that component wherever I want without having too worry too much about the css breaking.

bart

comment number
date
April 16, 2010 05:01

Have you guys seen http://oocss.org/? I think the approach they take is similar to yours, Niels. I've never personally used css that way. I've always preferred .productList li over .productList .product...remember the dreaded classitis? I'm not really sure that it's all that bad now. I just remember reading about it being evil. Reminds me somewhat of the XHTML vs HTML debate. Everyone jumped on the XHTML band wagon because of some phantom benefits that later turned out not to be true. According to OOCSS, this: .sidebar h2 {} .main h2 {} are not good because h2 is not portable without context. The better thing to do is to extend h2 ie h2.sidebar {} or h2.main {} so it can be dropped in any context and retain its intended styling. Now semantically speaking, the names/contexts .sidebar and .main are misleading. Would be nice to know what the correct solution is.

Niels Matthijs

comment number
date
April 16, 2010 13:50

It all depends whether something "needs" to be portable. Some elements need to behave according to their context, others have their own particular styling and need to be displayed independent of their context.

Headings are usually dependent on their context, other elements (like confirmation boxes) are usually independent of their context.

As for classitis, it is currently the only way to create (non-standardized) semantics, so I don't mind a single bit.

* required fields

Leave your data
Leave a comment