What's so great about Twitter Bootstrap?
I’ve been a pretty big fan of Twitter Bootstrap since it came out. I’ve used it for Pixel Publish and for the early prototypes of TicTalking. However I’ve never really talked much about it on my blog and I wanted to explain a bit about why I feel Bootstrap is an absolutely invaluable tool, in particular, for developers who are just getting their feet wet in the world of web design and want to “bootstrap” their learning.
Modular CSS is awesome
One of the things that most developers struggle with early on with web development (well I know I did anyways) is how to keep design modular. By that I mean, separated, decoupled and reusable, all of the same attributes we like to see in good code are just a relevant in our CSS and HTML. In fact this is crucial if you plan to be able to work on the same HTML and CSS with other people concurrently (just as is true for code).
I recently attended Jonathan Snook’s SMACSS workshop to get more in-depth into good CSS and HTML structure. SMACSS stands for Scalable and Modular Architecture for CSS. Snook mentioned that when he first took a look at the CSS for Bootstrap he immediately recognized it as similar to his SMACSS approach, even though the author’s of Bootstrap claimed to have never heard of Snook’s guide. In other words well structured CSS is instantly recognizable and Bootstrap comes with it built in.
Learning to write good modular CSS is hard. I mean CSS is pretty much pure insanity to begin with and all SMACSS really does help to bring a modicum sanity to it, but lets face it, no one should expect that running the asylum will be an easy task.
If you’re even moderately familiar with CSS, it’s very likely that Bootstrap has a lot to teach about modular CSS architectures simply by way of example. Personally I’ve learned more about CSS and more importantly well organized and structured CSS in 3 months or so of working with Bootstrap than I ever knew, in fact I’ve probably forgotten more about CSS in the past 3 months than I ever originally knew too. Bootstrap isn’t just a good way to bootstrap your project or site, it’s also a great way to bootstrap learning about HTML and CSS and design language.
Use a common design language
The web is full of commonly seen and repeated patterns of design. Things like header menus, navigation, dropdowns, button groups, progress bars, labels, alerts, image thumbnail boxes, etc. The list of simple web design patterns that Bootstrap comes with out of the box is impressive.
Snook likes to call these “modules” in SMACSS terms. Bootstrap gives you a plethora of great working examples of these and how to keep these modules clean and reusable. For this reason alone Bootstrap is invaluable for learning to write CSS. The added bonus is that having so many of these patterns at your fingertips is also great for prototyping productivity. So it’s efficient learning with no lost productivity, tastes great less filling!
I highly recommend checking out the Bootstrap documentation and seeing for yourself. A few designers I’ve shown this too loved seeing all the design language laid out and exposed this way. In fact I’d go so far as to suggest that every project should have this sort of a living documentation. It’s great for facilitating design communication and helps to bring new team members up to speed quickly.
Responsive design is totally trendy
Responsive design is the new hotness in web design and I friggin’ love it. I’ve always been bugged by sites that didn’t work well or look good on my phone (or a tablet for that matter). One of the big selling points of Octopress for me was a completely responsive design (so if you’re reading this from your phone, you’re welcome). Mobile only versions of sites are often neglected or restrictive, or just plain boring.
Responsive design is about transforming site layout appropriately for any form factor and Bootstrap just comes with it, in that “it just works (tm)”. Responsive design is something everyone should learn and once again Bootstrap provides a great way to see how it’s done.
I also love their use of data-api attributes to allow these components to be
used transparently and without relying on manually attaching them via
data-toggle="collapse" to something you want to be a collapsible section and
$ () -> $('body').on 'focus.location.data-api', '[data-location=true] textarea', (e) -> form = $(this).closest('form'); location_field = form.find('.location') longitude_field = form.find('.longitude') latitude_field = form.find('.latitude') geo = new Geocoding() geo.locate (coords) => latitude_field.val coords.latitude longitude_field.val coords.longitude geo.reverseGeocode coords, (results) => location_field.val results
I use this to automatically add geolocation data alongside any textarea that
specifies it expects it via the
data-location="true" attribute. When the
textarea is focused this component will attempt to obtain the current location
and populate some hidden latitude, longitude and location text fields. The
Geocoding class is just a simple geolocation feature wrapper since I find the
API to be a bit weird.
We have lots of components for various purposes, some are copied (though modified somewhat) from Bootstrap, like our tab control and collapsible elements. Others are specific to our site, like the component that handles toggle buttons for following/unfollowing someone. Often these components fire events off whenever they do something and we can use those events to customize and extend the behaviors further using Backbone (or whatever) in an open-closed principle sort of way.
Growing up and moving on
Bootstrap has been a efficient way to both prototype designs and to learn modular CSS, HTML and JS but I now feel ready to go out into the world on my own, build my own stuff without Bootstrap’s assistance. I feel much more confident and able to implement custom designs in a modular way, to break them down into separate components and modules of style, layout and behavior and I can keep things much more sane and manageable.
Bootstrap really lives up to it’s name in more ways than one. Sure it’s not perfect and I’ve had frustrations and complaints with this and that, but what is? Bottom line is, if you’re looking for a way to level up your HTML, CSS and JS there are certainly worse frameworks you could be learning from.