Developer News

A Strategy Guide To CSS Custom Properties

Css Tricks - Wed, 05/16/2018 - 4:05am

CSS preprocessor variables and CSS custom properties (often referred to as "CSS variables") can do some of the same things, but are not the same.

Practical advice from Mike Riethmuller:

If it is alright to use static variables inside components, when should we use custom properties? Converting existing preprocessor variables to custom properties usually makes little sense. After all, the reason for custom properties is completely different. Custom properties make sense when we have CSS properties that change relative to a condition in the DOM — especially a dynamic condition such as :focus, :hover, media queries or with JavaScript.

Direct Link to ArticlePermalink

The post A Strategy Guide To CSS Custom Properties appeared first on CSS-Tricks.

Css Tricks - Tue, 05/15/2018 - 11:25am

The team at Figma has created a new resource for “learning, creating and evangelizing design systems” called Design Systems that already has a good collection of interviews and articles by some folks thinking about these things.

I particularly liked Jeroen Ransijn’s post on how to convince your company it’s ready for a design system, where he writes:

Building a design system is not about reaching a single point in time. It’s an ongoing process of learning, building, evangelizing and driving adoption in your organization.

Design systems are a popular topic. Ethan Marcotte recently looked at instances where patterns get weird, Lucan Lemonnier shared a process for creating a consistent design system in Sketch, and Brad Frost debunked the perception that design systems are rigid. Seems like Figma's new site will be a nice curated repository of this ongoing discussion.

Direct Link to ArticlePermalink

The post appeared first on CSS-Tricks.

Five of My Favorite Features of Jetpack

Css Tricks - Tue, 05/15/2018 - 6:37am

Jetpack is an official WordPress plugin directly from Automattic. It's an interesting plugin in that it doesn't just do *one thing* — it does a whole slew of things that enhance what your WordPress site can do. *Any* WordPress site, that is, and often with extremely little effort. Those easy win features Jesse Friedman calls light switch features, meaning you literally flip a switch in Jetpack's settings and start benefitting. I love that.

There are dozens of features in Jetpack, and I personally make use of most of them and see the benefit in all of them. Allow me to share with you five of my favorites and how they are actively used right here on this site. It's actually a bit hard to pick, so perhaps I'll do this again sometime!

1) Related Posts

This seems like such a simple little feature, but it's anything but. Something has to analyze all the content on your site and figure out what is most related to the current content. That kind of thing can be incredibly database intensive and bring even powerful hosting to its knees. WP Engine, by all accounts a powerful and WordPress-tuned host, bans many of them outright:

Almost all “Related Posts” plugins suffer from the same fundamental problems regarding MySQL, indexing, and search. These problems make the plugins themselves extremely database intensive.

Their top recommendation? Jetpack Related Posts.

Jetpack handles this by offloading the work off your servers and onto theirs. Your site has no additional load for this super useful feature. I find it does a great job.

In a recent post about dropdown menus, here are the related posts it displays. 2) Markdown

I wrote once: You Should Probably Blog in Markdown.

I'm quite serious about that. I've been involved with far too many sites where old content was mired with old crufty HTML or otherwise formatted in a way that held them back, and cleaning up that content was an impractically large job. You avoid that situation entirely if you create your content in Markdown (and stick to Markdown syntax).

Things like <span style="font-weight: bold; font-family: Georgia; color: red;"> around seemingly random sentences. <div class="content-wrap-wrap"> wrapping every single blog post because it was just “what you did”. Images force-floated to the right because that made sense three designs ago. Headers with class names on them that don’t even exist anymore. Tables of data spit into content with all the whitespace stripped out and weird alignment attributes you barely recognize. An about page that was pasted in from Microsoft Word.

Content like this will not and cannot last.

With Jetpack, you flip on Markdown support and you're good!

Almost more importantly, it feels like the Markdown option you can trust. There are other plugins out there that add Markdown support, and that's great, but they leave open questions. How long is the plugin going to be supported? What variety of Markdown did they pick? Is that variety going to continue to be supported? Does it work in comments? These kind of questions make me nervous.

Choosing Jetpack feels safe because it's the official Markdown choice of WordPress, in a plugin we can be sure will be updated forever.

It'll be interesting to see what Markdown + Gutenberg is like!

3) Social Sharing

This is a multi-pronged feature.

One, it can easily add sharing buttons to your posts. This isn't a particularly difficult thing to do for any developer worth their salt, but having it abstracted away in a plugin is nice.

Two, it can share your posts directly to social sites like Twitter and Facebook. That's a much harder thing to write from scratch. It's a thing I used a paid third-party service for years. It was a pleasant surprise when I discovered Jetpack's ability to do this.

The "official" buttons can be nice as they have the most integrated functionality with the services themselves, but I dig that the other options are like "Responsible Social Sharing Links" in that they have the least possible performance overhead.

It allows you to customize the mesasge, and does smart stuff like includes the Featured Image as image attached to the social post.

4) Comment Improvements

I'm a little uncomfortable using a third-party comment system on my sites. I like control. Comments are content and I like making sure those are in my own database. Yet, I think users have a little higher expectations of comment thread UX than they used to. Having to manually type in your name and email and all that feels kinda old school in a not-so-great way.

Fortunately, Jetpack can replace your comment form with a modernized version:

Now users can log in with their social accounts, making leaving a comment a much easier flow. Not to mention the fact that it's all the less work you have to do styling the comment form.

Notice the "Notify me of new comments via email" checkbox there too. Guess what powers that? Jetpack. That's a nice feature for people who are leaving question-style comments on your site. They very likely want to be notified of about the conversations happening in comments as it evolves.

5) Security

I've been deep into the world of web development for many years. The more I know, the more I can see that I don't know. We all have to focus on certain things to get done what we need to on our own journeys. I fully admit I know very little about server-side web security. I'd rather leave that exertise to others, or ideally, software that I trust.

Here's some fun statistics from here on CSS-Tricks:

It's nice to know my site is being protected that way from malicious logins. Spam, an even more direct problem, is also taken care of by Akismet, the spam-blocking plugin that my Jetpack subscription covers.

Should anything happen to the site, I know it's backed up off my server by VaultPress, which is also part of my Jetpack subscription.

See how much it does!?

Again, this is just a handful of the features of Jetpack. There are so many niceties tucked into it I consider it a no-brainer plugin. Probably the first and most important plugin you'll install on any self-hosted WordPress site.

The post Five of My Favorite Features of Jetpack appeared first on CSS-Tricks.

It All Started With Emoji: Color Typography on the Web

Css Tricks - Tue, 05/15/2018 - 4:02am

“Typography on the web is in single color: characters are either black or red, never black and red …Then emoji hit the scene, became part of Unicode, and therefore could be expressed by characters — or “glyphs” in font terminology. The smiley, levitating businessman and the infamous pile of poo became true siblings to letters, numbers and punctuation marks.”

Roel Nieskens

Using emojis in code is easy. Head over to emojipedia and copy and paste one in.


Or in CSS:

And JavaScript, too:

(Alternatively, you can specify emoji with a Unicode codepoint.)

However, you might run into a problem...

Lost in translation: Emoji’s consistency problem

The diversity of emoji across platforms might not sound like a major problem. However, these sometimes radical inconsistencies leave room for drastic miscommunication. Infamously, the “grinning face with smiling eyes” emoji ends up as a pained grimace on older Apple systems.

This was such a big deal that even The Washington Post covered it.

A harmless and playful watergun emoji might show up as a deadly firearm.

Courtesy of Emojipedia.

And who knows how many romances were dashed by Google’s utterly bizarre hairy heart emoji?

&#x1f92e;This has since been rectified by Google

Unicode standardizes what each emoji should represent with a terse description but the visual design is down to the various platforms.

Color fonts to the rescue!

The solution? Use an emoji font. Adobe has released a font called EmojiOne and Twitter open-sourced Twemoji. More are likely to follow.

@font-face { font-family: 'emoji'; src: url('emojione-svg.woff2') format('woff2'); }

If a user types into an HTML input or textarea, they will see your fancy custom emoji. ❤️

An input in Firefox.

Emoji fonts also have the benefit of avoiding the pixelation seen in scaled-up raster emoji. If you happen to want really large emoji, an SVG-in-Opentype font is clearly the superior choice.

On the left, a standard Apple dogface emoji looking pixelated. On the right, smooth SVG-in-Opentype emoji characters from Emojione and Twemoji, respectively. Unicode (right) clearly doesn’t specify a breed! Browser support

Confusingly, color fonts aren’t one standard but rather four &#x1f644;. OpenType is the font format used on the web. When emoji were added to unicode, the big players realized that multi-color support needed to be added to OpenType in some way. Different companies came up with a diversity of solutions. The fonts are still .ttf, .woff or .woff2 — but internally they’re a bit different. I pieced together this support table using a tool called Chromacheck:

Chrome Safari Edge Firefox SVG-in-Opentype ❌ ❌ ✅ ✅ COLR/CPAL ✅ ✅ ✅ ✅ SBIX ✅ ✅ ✅ ❌ CBDT/CBLC ✅ ❌ ✅ ❌

We’ve learned why color fonts were invented. But it’s not all about emoji...

Multicoloured alphabets Gilbert font

Color fonts are a new technology, so you won’t find that many typefaces to choose from as of yet. If you want to try one out that’s free and open source, Bungee by David Jonathan Ross is a great choice.

While some fonts provide full emoji support and others offer a multicolor alphabet, Ten Mincho — a commercial font from Adobe — takes a different tack. In the words of its marketing material, the font holds “a little surprise tucked away in the glyphs.” Of the 2,666 emoji in the Unicode Standard, Ten Mincho offers a very limited range in a distinctive Japanese style.

The adorable custom emoji set of Ten Mincho

Emoji have become a predominant mode of human communication. Over 60 million emoji are used on Facebook every single day. On Messenger, the number is even more astonishing, at five billion per day. If you’re building any sort of messaging app, getting emoji right really matters.

The post It All Started With Emoji: Color Typography on the Web appeared first on CSS-Tricks.

Free Introduction to Web Development Workshop

Css Tricks - Tue, 05/15/2018 - 3:54am

Brian Holt and the Frontend Masters team are putting on a free workshop today and tomorrow that is live-streamed for anyone that's interested. This is super cool because, despite the fact that there is a mountain of articles about web development out there, there are only few that start with the basics in a manner that's easy for beginners to follow. All of the materials are open source and available here as well.

I've been a fan of Brian's work for ages now, which is part of the reason why I advocated for him to join my team, and now I have the honor of working with him. I find his style of teaching really calming, which is encouraging when the subject forays into complex concepts. The livestream is free today (5/15) and tomorrow (5/16), but will also be available afterwards if you happen to miss it.

Direct Link to ArticlePermalink

The post Free Introduction to Web Development Workshop appeared first on CSS-Tricks.

Google Conversions: Highlights

LukeW - Mon, 05/14/2018 - 2:00pm

Across several presentations at Google Conversions in Dublin, several speakers shared insights and best practices for conversion rate optimization. Here's a few highlights:

Confirmation Bias - Michael Aagaard
  • In the 18th century, tobacco smoke was considered very good for your heart and lungs. In particular tobacco enemas were quite popular so much that they were placed along the banks of the river Thames to help drowning victims. This is an example of confirmation bias at work.
  • Confirmation biases is our tendency to accept evidence we agree with at face value and dismiss information we don't agree with unless the evidence is overwhelming. Confirmation biases limits our ability to seek out and uncover the truth.
  • Torturing data: if you torture any data long enough it will confess to anything. High levels of correlation between things don't imply causation. We have to be careful to not see what we want in data.
  • Stopping A/B tests when they show the impact we want is an example of confirmation bias. Instead, let them run for an appropriate amount of time. Over time, tests are likely to show much less effects.
  • How to overcome confirmation bias: accept the fact that you could be wrong, seek out a different perspective. Find people who talk to customers/users. They have a bias toward end users.
  • Don't test your ideas, do detective work to find out what customers need and how they talk about it. Then your A/B test is simply the final test at the end to see if you did your detective wrok well.
CRO - Lina Hansson
  • Celebrate the discovery of weak spots. Don't take it as failure but instead be happy when you find something that can be improved.
  • The biggest missed opportunity in conversion rate optimization is usability testing. Move away from opinions and instead use user testing to identify issues.
  • A common pain point across retail sites is find-ability: both search and browse. When we move to mobile, many sites remove their top categories list in order to fit on smaller screens. This creates discoverability issues. One of the first things retail sites should test is adding categories visibly on their home page.
  • Value propositions for companies are usually cut for mobile. Instead of removing them, redesign them to make them work on mobile.
  • People can be classified into four behavior types. Methodical people read completely and analyze before making decisions. Humanistic people react strongly to the opinions of others. Competitive people move quickly and expect things to work. Spontaneous people are emotional and fast-paced. You can design experiences that are appropriate for each of these behavior types.
  • The companies that solve checkout on mobile are the ones that will win.
Meaningful Data - Simo Ahava
  • It's quite simple to get a service like Google Analytics set up but how do we use these tools to really understand what we're doing. How can data become meaningful?
  • Tactics (tool expertise) without a strategy (business expertise) are just party tricks and a strategy without tactics is just talk. What brings the two together is agility.
  • Tools must be customized for your organization's needs. We are not trying to optimize metrics but our businesses. Default metrics and reports need to be adjusted to work with your specific needs.
Landing Pages - Anna Potanin
  • Designers want to do their best and create unique interfaces but making things for the Web often requires understanding and using conventions. Only apply a unique visual design after you have followed best practices.
  • 3 things all retail sites should have on their landing and home pages: call to action, value propositions, and visuals.
  • The more prominent you make your search bar, the more searches you get. Why do you want to do this? Conversion rates are usually much higher for people who search

Page Transitions for Everyone

Css Tricks - Mon, 05/14/2018 - 3:55am

As Sarah mentioned in her previous post about page transition using Vue.js, there is plenty of motivation for designers and developers to be building page transitions. Let's consider mobile applications. While mobile applications are evolving, more and more attention is given to the animation experience, while the web pretty much stays the same. Why is that?

Maybe it’s because native app developers spend more time working on those animations. Maybe it’s because users say that’s what they want. Maybe it’s because they know more about the environment in which the app is going to run. All of that helps to improve the experience over time. Overall, it seems like mobile app developers somehow seem to know or care more about user experience.

If we take a look at how mobile apps are designed today, there is very often some sort of animated transition between states. Even ready-to-use native components have some kind of simple animation between states. Developers and designers realized that this little animation helps a user grasp what is happening in the app. It makes the navigation through the app easier and tells the user where they are going within the app.

For example, when you’re navigating to a subcategory, it usually slides in from the right side of the screen, and we all somehow know what that means.

Animation matters. It can be used to improve the user experience.

When you’re developing a website, it’s easy to spend hours making sure the user sees the whole story by way of top-notch transitions, like the movement between gallery pictures or fancy hover effects...but once a user clicks a link, all of that experience falls apart and you’re starting from the beginning. That’s because the page reloads and we don’t have an easy/obvious/native way to handle animations/transitions in that situation.

On the web, most of the effort used to improve the experience is in structure, visual design, or even the performance of the site. There are some elements you can swipe around here and there, but that’s about it. A boring remnant of the time when the web was simply used to navigate through a bunch of text pages later upgraded with some sliding text.

Yes, we actually used to do this.

There are some very fancy websites that are filled with animation or incredible WebGL hieroglyphs in the background. Unfortunately, they are often hard to navigate and your laptop battery is drained in about 15 minutes. But they are certainly nice to look at. Those sites are full animation, but most of it is used to impress you, and not to help you navigate around, or make the experience faster, or make things more accessible for you to browse the site.

The Source of the Problem

All of this raises a big question. We have all the technology to do this page transitions stuff on the web. Why don’t we do it? Is it because we don’t want to? Is it because we don’t think that’s part of our job? Is it so hard that we’d have to charge double for projects and clients aren’t buying it?

Let’s take a look at another possible reason. Often, a company chooses technologies that are common for all of their projects. You, as a front-ender, don't have much control over what’s implemented on the server, so maybe you can't count on some server-side rendering of your JSX.

Maybe you have to choose something stable and generally usable for any sort of solution (which usually means the less codebase, the more flexible), so you’re kind of forced to avoid some framework in your development stack. Unfortunately, it makes sense. You don’t want to implement a contact form in 10 different frameworks just because you’ve decided that some framework is a good base for this particular project. And don't get me started on security, which has been in the process of being improved throughout the years. You cannot just throw it away because you want your user to have a bit more fun browsing your site.

There is another possible reason. Maybe you want to build on WordPress because you want to take advantage of all those open source goodies people prepared for you over the years. Would you exchange all of that "free" functionality for a better experience? Probably not...

The Goal

Aside from drastic and unrealistic changes like getting rid of all images and videos, our website load time from the server just is what it is. We have a server rendered page, and apart from a faster server or better caching, there isn’t much to do to improve that.

So the way to improve the load time is to cheat a bit! Cheat by making the user think it takes less time because they are distracted by what’s happening on the screen. Cheat by loading the content ahead of time and animating the transition.

Let’s introduce some effects that could be used to do the transition. Even simple fade in/fade out can give you a whole different feel, especially with some element indicating loading. Let’s look at some examples.

Note: All of following examples are websites build on PHP and pretty much work without JavaScript as any other site would.

Source: (public production site)

A simple fade out/fade in seamlessly improves experience user has before the click of the link and doesn't act that disturbing as a normal browser reload would. The loading indication on a menu icon ensures a user doesn’t panic in case the page takes little longer to load.

Some interesting animation can be achieved by animating different elements in different ways, which can also be combined with fading.

Source: (public production site)

Or how about covering up the page with some other element?

Source: (public production site)

Those few hours of work give the website whole new feel by turning your static page into an animated one. And that's without any additional preparation.

However, in case you are already aware of your intention in the design phase, you can adjust the design to your needs. Common elements can be prepared ahead of time.

Source: (company internal system)

The main navigation element introduced in a form of bubbles plays with the user while the content of the next page is loading. The impact is that user is not bored and knows that something is happening. As the animation starts on the click of the link, the user doesn't even realize he’s been waiting for something.


We have sorted out what we actually want to do, and why do we want to do it… let’s see how can we achieve this.

While there is not much to do on the back-end for this, there is a whole bunch of things you can do on the browser side. A good example is Turbolinks, developed by the Basecamp folks, which takes your website and makes it more app-feeling by enabling content loading with JavaScript. It simply avoids that ugly browser page-to-page reloading jump. Turbolinks deals with browser history, loading, and all that other stuff that would normally happen under the hood of the browser. The key thing here is taking control over loading and replacing content because as long as the browser doesn’t reload, everything that happens on a screen is in our control.

Let’s think of some concepts we can use to improve our experience. The load time is our biggest enemy, so how can we improve it in the browser?


In most cases, the request for loading the next page doesn't have to start only once a user clicks the link. There is another event happening that can indicate users intention to visit the page, and that’s a hover over the link. There are always few hundreds of milliseconds between hover and click on the link, why not use that time to our advantage? Heck, if the majority of your users end up on the next page that is known to you and you have the statistics to prove it, why not even preload it any time after the initial render, while the user is trying to get around the current page?

The following diagram illustrates how many things can happen in parallel and save us some of that precious time, instead of being done one by one. A very common mistake seen in custom solutions for page transition that people make for themselves is the start of the request, which is usually triggered after the page is unloaded/hidden.

Possible process of transition Caching

While this can be a problem for some dynamic sites, static sites are perfect candidates for caching. Why would you load a page twice, when you’re in control of loading and replacing the content? You can save the contents and use it in case the user visits the same page or returns to it with the browser back button.

Or, you can use the cache to preload pages on hover and empty the cache regularly (maybe after each page visit?) to always have the latest version of the page on dynamic sites while still enabling that preload feature.

Interestingly, Progressive Web Apps also "invest" in this area, although the approach is a bit different.


All these concepts are great, but we still need to bring animations to the party.

The control of the page load and replacement can be taken over by us, thus we can play with the contents of the page at any given time. For example, it’s simple enough to add a class to the page while it's loading. This gives us the ability to define another state for the page, or in other words, hide/unload it. When the animation is done and the page is loaded, we are free to replace the content and remove the state class to let the page animate back in again.

Another option is to animate your page "out" with JavaScript, replace the content, and animate it back "in."

There are many possibilities of how to approach this, but in any way, the key feature here is not letting the browser reload.

Ready to Go

Those are three main concepts that will make a lot of difference. The point is, with a little extra effort, it's not that hard to do this yourself, and I encourage you to do so.

It's going to be a bumpy road with loads of possible headaches, as it's not always easy not to break the browser’s native functionality.

However, if you’re more of a load and go type of person, I have put together a little package called swup that sorts out all of those things that Turbolinks does, plus all three of the concepts we’ve covered here. Here's a little demo.

What are the perks of swup?

  • It works exclusively on the front-end, so no server setup is required. Although you can easily implement a transfer of only required data based on X-Requested-With in the request header (little modification of swup is required based on your particular solution).
  • Uses browser history API to ensure correct functionality of your site, as it would work without swup (back/forward buttons and correct route in the URL bar).
  • It does not have to be part of initial load batch and can be loaded and enabled after the initial render.
  • Takes care of the timing, meaning it automatically detects the end of your transitions defined in CSS and, in the meantime, takes care of loading the next page. The whole process is based on promises, so not a single millisecond is wasted.
  • If enabled in options, swup can preload a page when a link is hovered or once it’s encountered in loaded content (with the data-swup-preload attribute).
  • If enabled in options, swup also caches the contents of the pages and doesn’t load the same page twice.
  • Swup emits a whole bunch of events that you can use in your code to enable your JavaScript, analytics, etc.
  • You can define as many elements to be replaced as you want, as long as they are common for all pages. This enables the possibility to animate common elements on the page, while still replacing its parts. The bubble menu in our earlier example above uses this feature, where the check signs on the bubbles are taken from the loaded page, but rest of the bubble stays on the page, so it can be animated.
  • Gives you the possibility to use different animation for transitions between different pages.

For those of you that like your animation done with JavaScript, there is also a version for that called swupjs. While it may be harder to implement animations in JavaScript, it definitely gives you more control.


The animation and seamless experience doesn't have to be strictly limited to native applications or newest technologies. With little effort, time, and a bit of code, even your WordPress site can feel native-like. And while we already love the web the way it is, I think we can always try to make it a little better.

The post Page Transitions for Everyone appeared first on CSS-Tricks.

Ship Map

Css Tricks - Mon, 05/14/2018 - 3:54am

Interactive maps can both be functional and, when combined with data, tell a good story. Kiln released this data-driven map (make sure to hit the play button) to show the routes of every cargo ship moving about on the high seas in 2012.

Created by London-based data visualisation studio Kiln and the UCL Energy Institute

How something like this is created can be mind-boggling. Kiln has a service called Flourish that helps with the lifting and we recently shared Observable, which has a similar aim. Sarah wrote up an entire tutorial on creating serverless data visualizations.

Direct Link to ArticlePermalink

The post Ship Map appeared first on CSS-Tricks.

What’s wrong with CSS-in-JS?

Css Tricks - Fri, 05/11/2018 - 9:15am

Brad Frost thinks it's:

  1. Lack of portability
  2. Context Switching
  3. Flushing best practices down the toilet

In the spirit of good-ol-fashioned blog-and-response, here's:

I'd like to point out that "CSS-in-JS" is an umbrella term, and that there are lots of takes on actual implementations of this. It's possible to like one approach and not another.

My guess is we'll end up with a split down the middle as a best practice someday.

When we write styles, we will always make a choice. Is this a global style? Am I, on purpose, leaking this style across the entire site? Or, am I writing CSS that is specific to this component? CSS will be split in half between these two. Component-specific styles will be scoped and bundled with the component and used as needed.

Direct Link to ArticlePermalink

The post What’s wrong with CSS-in-JS? appeared first on CSS-Tricks.

Turn Sublime Text 3 into a JavaScript IDE

Css Tricks - Fri, 05/11/2018 - 4:40am

Sublime Text is one of the most popular editors for web development and software development in general. It’s very smooth and fast compared to other editors (being written in C++ helps that speed). Sublime also has tons of plugins you can find through Package Control.

But it’s only a text editor and not an IDE. An IDE is a software application that provides comprehensive facilities to computer programmers for software development. In fact, Sublime doesn’t offer features like debugging tools, built-in tools for compiling and running applications, intelligent code suggestions, or code refactoring. Instead it offers a set of APIs you can use to extend it. Here’s an introduction to the JavaScript Enhancement plugin (my own creation) that makes Sublime a bit more IDE-like for JavaScript development.

What is the JavaScript Enhancement Plugin?

It is a plugin for Sublime Text 3 that offers a lot of features useful for creating, developing, and managing JavaScript projects. The most important ones are:

  1. Smart autocomplete
  2. Error detection and linting
  3. Code refactoring

Several other features can be found on the Wiki page.

Most of the features are implemented using Flow under the hood, which is a static typechecker for JavaScript created by Facebook (if you know TypeScript, it is quite similar). The main objective of this plugin is to turn Sublime Text 3 into a JavaScript IDE. It is in active development and it will include other features over time.


There are two ways to install it. The simplest one is through Package Control, the other one is to install it manually following these simple steps.

  • Sublime Text 3 build 3124 or newer
  • Node.js (6 or newer) and npm
  • TerminalView Sublime Text plugin (Linux and Mac OS X only)
Supported Systems

Because Flow only works on 64-bit systems, this plugin supports:

  • Mac OS X
  • Linux (64-bit)
  • Windows (64-bit)
Smart Autocomplete

Sublime Text has its own autocomplete feature, but it lacks power, making it not nearly as useful as it could be. With this plugin, you will get autocompletion based on the current context, like any other IDE. For example, you will get completions from your imported classes defined in other files, such as properties and methods.

Furthermore, the completions list will also contain info about variables type and functions signature in order to get a quick overview of them.

Here’s how that works with the plugin:

...and without the plugin:

Error Detection and Linting

Sublime Text doesn’t have an error detection and/or linting system natively. Thanks to Flow, this can be done using its own CLI commands.

First of all, you need to create a JavaScript project (see the Creating a JavaScript Project wiki page). In order to let the Flow server check your files, you need to add a special comment in them: // @flow.

You can set also more options in the .flowconfig file (see the official website to customize your Flow configuration. For example, if you want to let the Flow server check all files and not just those with @flow, you need to set the all option to true:

[options] # all=off by default all=true

To let the Flow server check also single files that aren't part of a project, you can activate the option in Tools > JavaScript Enhancements > Use Flow checker on current view (Not used in project) for each Sublime View. In this case, the Flow server will see only the current view.

Instead, like is says on the official website, lint settings can be specified in the .flowconfig [lints] section as a list of rule=severity pairs. These settings apply globally to the entire project. An example is:

[lints] # all=off by default all=warn untyped-type-import=error sketchy-null-bool=off

Lint settings can be specified also directly in a file using flowlint comments. For example:

/* flowlint * sketchy-null:error, * untyped-type-import:error */ Code Refactoring

Sublime Text doesn’t offer a code refactoring system natively. This is realized with the help of Flow CLI commands in order to get the necessary information. At the moment, this plugin offers various code refactoring features, including:

Some of them can also have an available preview. Furthermore, features, such as Safe Move, will work only on JavaScript projects (also here, see the Creating a JavaScript Project wiki page).

Support Issues/Questions

If you have any problems, create an issue. Protip: do a quick search first to see if someone else didn't ask the same question before! For small questions, you can use Gitter.

Feature Requests and Enhancements

For feature requests, create an issue or use Gitter.

Financial Contributions

If this project helps you reduce time to develop and also you like it, please consider supporting it with a donation on Patreon, Open Collective or using PayPal. Thanks!

The post Turn Sublime Text 3 into a JavaScript IDE appeared first on CSS-Tricks.

How to build a slide deck in PowerPoint that isn’t god awful

Css Tricks - Thu, 05/10/2018 - 3:52am

"Oooh! A PowerPoint Presentation!"

— No one ever

Nobody likes a slide show. I don't even have to back that assertion up with evidence. It's a universal truth — like saying "the sky is blue", "the grass is green" or "The Mummy with Tom Cruise is the worst movie ever made." And if you haven't seen The Mummy reboot, I just saved you and you should be grateful.

It's as if there is some unwritten rule that says: if you do a PowerPoint presentation, it has to be measurably boring on a physical level.

It doesn't have to be this way. We can make engaging and (I hate this word but watch me use it anyway) delightful slide shows and you only need to know two things:

  1. How to work with shapes
  2. The "Morph" transition

Here is an example of the slideshow we're going to be building in this post. Almost all of this will be handcrafted — including most of the artwork. I think you'll be surprised at how easy it is to do. Let’s just say it’s about 1,000 times easier than sitting through "The Mummy 2017."

To get started, you need to first pick a template by not picking a template.

Pick a template and then don't pick a template

One thing that most people struggle with is just deciding on a template to use. You don't need a template, but you do need some creative inspiration. You can just look on the main PowerPoint template gallery for ideas. For the city theme, I took inspiration from this template.

Keep in mind that your template doesn’t have to be related to your content. If you juxtapose something like a spring time city theme with a concept like Serverless, it provides an upbeat and friendly backdrop on which to talk about a concept that might otherwise be intimidating.

Just looking through this template gallery, you can take inspiration from the "Drops" template to build an underwater theme, the "Parcel" template to build a package theme — maybe a pile of packages on a table that you can move through. I don't know. I can't come up with all the ideas here.

Now that you have inspiration, the next step is to copy a great artist.

Great artists steal

Steve jobs famously quoted Picasso by saying, "Great artists steal" and then didn’t give him the credit, which is the pinnacle of irony.

That quote is not entirely true. You can borrow ideas and even form, but if you borrow too much, you are just ripping it off. It's a fine line. But this is a PowerPoint presentation. Not an iPhone. It's not like anybody but the eight people in your talk are going to see this.

For the city, we can just Google and see what other people are doing. I usually Google and then put "png" along with the search result because I want a cartoon city. The PNG image format is used for pictures that have only a few colors, and those are usually cartoons and logos. What we’re looking for here is something that is as "flat design" as possible.

This one is perfect. Flat design is the best thing to ever happen to non-designers. You used to have to actually be able to draw things and make them look realistic and all 3-D and stuff. Thanks to Flat Design, you slap a white square on a page with a heart in the corner and call it an icon. Thanks, Flat Design!

It is super easy to replicate or build your own flat artwork with some simple shapes in PowerPoint, which is exactly what we’re going to do.

Building the city with shapes

We’re going to replicate that city PNG image from our Google image search with nothing but shapes and our own Steve Jobs drive to steal art. For starters, just set the background of the slide to a light blueish green. We use a linear gradient turned 90° so that it becomes vertical, putting the white at the bottom so it looks more like light is coming from behind the buildings.

Our first building is just a rounded rectangle from the "Insert Shape" menu. We can let it sit just off the edge of the slide instead of having to get the bottom perfect. This is our first building so it’s also slightly off the screen to the left.

Most of our buildings are the same basic shape. We can copy this one, resize it and change the colors to get more buildings. I heavily "borrow" colors from my image inspiration. Having a great color palette will make all of the difference in the end.

OK! Now let’s add in some simple rectangle buildings. You may have to right-click and adjust the z-index ordering of the buildings selecting "Send To Back / Send Backward."

Our last building has a little spire on top. This is creating by adding a rounded rectangle for the building, one for the top and the one for the spire. You can adjust how rounded they are by dragging the little yellow square. I have split them out here so you can see what each looks like.

Then just put the shapes together. This is like LEGO only it didn’t cost you $180 bucks.

Beautiful! Now let’s add some windows to these buildings. Guess what you make windows out of? That’s right — more rounded rectangles.

Add in a small black rounded rectangle the runs the length of the first building. Then just copy and paste them down until you have a whole building’s worth.

Now the windows look a little wonky because they are not perfectly aligned. There are a few ways to fix this. You can zoom in using the little zoom slider in the bottom of the window. You can also select all the windows and then right-click and select "size and position." This opens up the sidebar and you can set the horizontal position "from" to 0. This will pull them a bit off the building so just adjust until they are centered.

Now repeat this for each building, using the original image for inspiration. Look at how they are doing windows. Some are long, some are square and some are in groups.

When you are done, you will have buildings with windows and guess what — they actually look like buildings!

Let’s add some hills and trees. These are just shapes too. The hills are stretched out green ovals. The trees are thick lines with green circles on top. Remember, people are expecting a PowerPoint presentation here, so the bar is already pretty low.

We need a few clouds. For that, we’re going to use the You don’t have to use Noun Project, but I find that a subscription is well worth all of the icons that I get. But you could very well just Google "cloud png."

The other cool thing about Noun Project is that you can get your icons in different colors. Now that we have clouds, we just insert a few and adjust their size.

What if all of our slide text looks like it was written in clouds? For this slide, the sky is all we have to work with, so a cloud font would work perfectly. There are a lot of font sites out there, and I ended up using one called "JFRockSolid." It’s supposed to be rocks, but when you make it white it looks like clouds. At least it looks like clouds to me.

Well, now that I’ve typed it out, it looks like rocks. DAMMIT.

We’re getting so close to being done! Let’s add in one more thing — a plane towing a banner with our subtitle on it.

For the plane, I just googled for "cartoon plane png." I wanted something with a few more colors and details. Sometimes we can build these things, sometimes we can use the Noun Project, and sometimes we just straight up rip off images from Google. Again, this is a technical presentation, not a customer-facing product. It’s also nice to include a slide at the end which gives credit for all the images you used. Be nice.

I just resized the plane and flipped it horizontally. Note that in order to flip images horizontally in PowerPoint, you have to use the 3-D Rotation on the x-axis. I know, so intuitive.

For the banner the plane is towing, we can use the "wave" shape.

Now, how do we add some text to this wave shape so that the text follows the ripple of the shape? This is a banner being buffeted by the wind, so our text would look silly if it’s just flat on the banner. Don’t believe me?

I told you. So, how do we do this? Well, for the first time your life, the answer is "Word Art."

Word Art acts like a shape, so we can skew it. I just add the first Word Art type and then remove the shadow and change the color. Then, under "Text Effects" you are going to select "ABC Transform." Then look for the shape that most closely resembles the one you want to align to. In our case, the shape is "wave 1."

Now just adjust your text shape using the little drag handles until it looks good on the banner. Change the font if that feels right. I’m using "Bernard MT". It’s not perfect, but it’s a huge improvement.

Connect the plane to the banner with a "curve" shape.

You’ll need to click to start the line and then click everywhere along the path between the plane and the banner where you want a curve. To end the line, hit the "escape" key. You’ll screw it up the first time, then you’ll get it.

And with that, we have wrapped up our first slide and done most of the hard work. It looks goofy in the presentation space, but here is what it will look like when you actually start the show.

"Burke — this does not look anything like a proper PowerPoint presentation."

Thank you. Thank you very much.

We’re now ready to begin building our show by zooming in and out of the city. The only transition we are going to use is going to be "Morph."

Using the Morph transition

The Morph transition animates objects to a new location or size. The key is to make sure you have the same objects between slides. Morph needs a reference to the element to be animated so it has to be an exact duplicate.

Morph is a cool name. I’m going to name my next kid Morph. Morph Holland. Yikes. That looks way worse on paper than it sounded in my head.

Duplication is the name of the game here. Duplicate the first slide by right-clicking and selecting "Duplicate slide."

Now we’re just going to play a game of moving things around and making them either bigger or smaller. And because most of our images are just shapes, we can resize them without degrading image quality.

The easiest way to move all these shapes is to group them into the left and right side by selecting several images and then right-click and select "group." Here is how I have mine grouped...

Make the following moves….

  1. Move the left group of buildings and hills almost all the way off the slide.
  2. Move the plane and banner group off to the slide to the right.
  3. Move the existing title off the top of the slide
  4. Copy the title and then move the copy back onto the slide and change the text

You slide should look something like this…

Now copy the new title text "Main Point I Want To Make" and paste it on the first slide. Then move it down to the bottom of the slide. Your first slide will now look like this…

On the second slide and select the "Transitions" tab and use the "Morph transition. Watch the magic unfold!

You can experiment with zooming in on any of the elements and then using that element as the slide background. For instance, maybe you have an image of an adorable pug that you want to show. You can animate individual elements with standard animations.

The rest is up to you. You can zoom in on buildings and use the windows for bullet points. Create a billboard and use that on the slide. I added a school bus (which I made with shapes BTW) just because school buses are awesome. I can say that now because I don’t have to ride one anymore. My kids would probably take serious issue with this.

Make something cool — because you can

Just like that you can create PowerPoint presentations that are so much fun to watch. People will wonder what the heck the slide is going to do next. They’ll stick around just for that. It does take some extra time to put together a high quality presentation, but on behalf of everyone who has ever sat through a PowerPoint presentation, I would like to thank you in advance.

If you would like to just grab and use this presentation (feel free to do so), you can download it here.

The post How to build a slide deck in PowerPoint that isn’t god awful appeared first on CSS-Tricks.

Locate and identify website visitors by IP address

Css Tricks - Thu, 05/10/2018 - 3:45am

(This is a sponsored post.)

Big thanks to ipstack for sponsoring CSS-Tricks this week!

Have you ever had the need to know the general location of a visitor of your website? You can get that information, without having to explicitly ask for it, by the user’s IP address. You’re just going to need a API to give you that information, and that’s exactly what ipstack is.

Here’s me right now:

This works globally through an API that covers over 2 million unique locations in over 200,000 cities around the world, and it’s update dozens of times a day.

It’s a nice clean JSON API for all you front-end JavaScript folks! XML is there too, if you need it. You’re probably curious about all the data you can get, so let’s just take a look:

{ "ip": "", "hostname": "", "type": "ipv4", "continent_code": "NA", "continent_name": "North America", "country_code": "US", "country_name": "United States", "region_code": "CA", "region_name": "California", "city": "Los Angeles", "zip": "90013", "latitude": 34.0453, "longitude": -118.2413, "location": { "geoname_id": 5368361, "capital": "Washington D.C.", "languages": [ { "code": "en", "name": "English", "native": "English" } ], "country_flag": "", "country_flag_emoji": "&#x1f1fa;&#x1f1f8;", "country_flag_emoji_unicode": "U+1F1FA U+1F1F8", "calling_code": "1", "is_eu": false }, "time_zone": { "id": "America/Los_Angeles", "current_time": "2018-03-29T07:35:08-07:00", "gmt_offset": -25200, "code": "PDT", "is_daylight_saving": true }, "currency": { "code": "USD", "name": "US Dollar", "plural": "US dollars", "symbol": "$", "symbol_native": "$" }, "connection": { "asn": 25876, "isp": "Los Angeles Department of Water & Power" } "security": { "is_proxy": false, "proxy_type": null, "is_crawler": false, "crawler_name": null, "crawler_type": null, "is_tor": false, "threat_level": "low", "threat_types": null } } What is this useful for?

All kinds of things! Whatever you want! But here’s some very practical ones:

  • Does your site display times? You can adjust those times to the user’s local time zone, so long as you know where they are.
  • Does your site display currency? You can adjust your prices to show local currencies, so long as you know where they are.
  • Does your site only work in certain countries due to laws, regulations, or other reasons? You might want to deliver different experiences to those different countries. ipstack is also often used for protection against potential security threats.

Lots of big companies like Microsoft, Airbnb, and Samsung use ipstack.


ipstack has a free tier covering up to 10,000 requests over a month, and plans start at a reasonable $9.99 a month covering 5 times that many requests and unlocking useful modules like the Time Zone and Currency modules. Plans scale up to any level, including millions of requests a day.

Direct Link to ArticlePermalink

The post Locate and identify website visitors by IP address appeared first on CSS-Tricks.

Where Lines Break is Complicated. Here’s all the Related CSS and HTML.

Css Tricks - Wed, 05/09/2018 - 11:43am

Say you have a really long word within some text inside an element that isn't wide enough to hold it. A common cause of that is a long URL finding it's way into copy. What happens? It depends on the CSS. How that CSS is controlling the layout and what the CSS is telling the text to do.

This is what a break-out text situation might be like:

The text hanging out of the box is a visual problem.

One possibility is overflow: hidden; which is a bit of a blunt force weapon that will stop the text (or anything else) from hanging out. Yet, it renders the text a bit inaccessible. In some desktop browsers with a mouse, you might be able to triple-click the line to select the URL and copy it, but you can't count on everyone knowing that or that it's possible in all scenarios.

Overflow is the right word here as well, as that's exactly what is happening. We have overflow: auto; at our disposal as well, which would trigger a horizontal scrollbar. Maybe suitable sometimes, but I imagine we'll all agree that's not generally an acceptable solution.

What we want is the dang long URL (or text of any kind) to break to the next line. There are options! Let's start with a place to attempt figure this stuff out.

Experimental Playground

My idea here is to have a resizeable panel of content combined with a variety of CSS property/values that you can toggle on and off to see the effects on the content.

This isn't comprehensive or perfectly executed, I'm sure. It's just some of the properties I'm aware of.

See the Pen Figuring Out Line Wrapping by Chris Coyier (@chriscoyier) on CodePen.

The Sledgehammer: `word-break: break-all;`

Allows words to be broken anywhere. The word-break property does "solve" the issue:

p { word-break: break-all; }

In an email exchange with fantasi, she explained that this works because the word-break property redefines what a word is. The break-all value essentially treats non-CJK as CJK, which can break just about anywhere (except stuff like periods and close parenthesis). The keep-all value does the reverse, treating CJK as non-CJK.

A Subtle Fix: `overflow-wrap: break-word;`

The overflow-wrap property seems to be the most effective solution for the problems we've laid out:

p { word-wrap: break-word; /* old name */ overflow-wrap: break-word; }

At first glance it might look very similar to the word-break: break-all; demo above, but notice how in the URL rather than breaking "pen" at "pe\n", it breaks at the end of that word where the slash is. Nicer.

fantasai explained:

"If a word can't break and would therefore overflow, then it can break anywhere to avoid overflow."

A Heavier Fix, Sometimes: `hyphens: auto;`

The hyphens property does what you might expect...allows for hyphenation in line breaks. Hyphens can sometimes do the trick in URLs and long words, but it's not guaranteed. A long number would trip it up, for example. Plus, hyphens affect all the text, breaking words more liberally to help text hug that right edge evenly.

p { hyphens: auto; }

fantasai told me:

"If a 'word' straddles the end of the line, we can hyphenate it."

I guess "word" helps put a finger on the issue there. Some problematically long strings aren't "words" so it can't be counted on to solve all overflow issues.

Future Sledgehammer: `line-break: anywhere;`

There is a property called line-break. It's mostly for punctuation, apparently, but I can't seem to see it working in any browser. fantasai tells me there will be a new value called anywhere which is:

"like word-break: break-all; except it actually breaks everything like a dumb terminal client"


Other HTML Stuff
  • The <br> element will break a line wherever it renders. Unless it's display: none;!
  • The <wbr> element is a "word break opportunity" meaning a long word that would normally cause an annoying overflow issue could be told that it's ok to break at a certain point. Useful! It behaves like a zero-width space.
Other CSS Stuff
  • The &shy; character is just like the <wbr> element.
  • You can inject a line break via pseudo element like ::before { content: "\A"; } as long as elment isn't inline (or if it is, it needs white-space: pre;)

The post Where Lines Break is Complicated. Here’s all the Related CSS and HTML. appeared first on CSS-Tricks.

Overriding Default Button Styles

Css Tricks - Wed, 05/09/2018 - 4:05am

There are a variety of "buttons" in HTML. You've got:

<button>Button</button> <input type="button" value="Button">

Plus, for better or worse, people like having links that are styled to match the look of other true buttons on the site

<a href="#0" class="button">Button</a>

One challenge is getting all those elements to look and layout exactly the same. We'll cover that a few ways.

Another challenge is getting people to use them correctly

This is a bit surprising to me — but I hear it often enough to worry about it — is that more and more developers are using <div>s for buttons. As in, they just reach for whatever generic, styling-free HTML is handy and build it up as needed. Andy Bell explains why a real button is better:

So, <button> elements are a pain in the butt to style right? That doesn’t mean you should attach your JavaScript events to a <div> or an <a href="#"> though. You see, when you use a <button>, you get keyboard events for free. You’re also helping screen reader users out because it’ll announce the element correctly.

And here's Andy again helping you out with a chunk of CSS that'll get you a cleanly styled button:

See the Pen Button Pal — some basic button styles by Andy Bell (@hankchizljaw) on CodePen.

It's that styling that just might be the mental roadblock

It's a bit understandable. Buttons are weird! They have a good amount of default styling (that come from the "User Agent Stylesheet") that varies from browser to browser and means you have work to do to get them exactly how you want.

See all the weirdness there?

  • Without any styling, the button is kinda little and has that native border/border-radius/box-shadow thing going on.
  • Just by setting the font-size, we lose all those defaults, but it's got a new default look, one with a border and square corners, a gradient background, and no box-shadow. This is essentially -webkit-appearance: button;.
  • Buttons have their own font-family, so don't inherit from the cascade unless you tell it to.

Here's Chrome's user agent stylesheet for buttons:

Firefox behaves a bit differently. See in the video above how setting border: 0; removed the border in Chrome, but also the background? Not the case in Firefox:

I only point this out to say, I get it, buttons are truly weird things in browsers. Factor in a dozen other browsers, mobile, and the idea that we want to style all those different elements to look exactly the same (see the opening of the article), and I have a modicum of empathy for people wanting to avoid this.

Never hurts to consult Normalize

Normalize does a good amount:

/** * 1. Change the font styles in all browsers. * 2. Remove the margin in Firefox and Safari. */ button, input, optgroup, select, textarea { font-family: inherit; /* 1 */ font-size: 100%; /* 1 */ line-height: 1.15; /* 1 */ margin: 0; /* 2 */ } /** * Show the overflow in IE. * 1. Show the overflow in Edge. */ button, input { /* 1 */ overflow: visible; } /** * Remove the inheritance of text transform in Edge, Firefox, and IE. * 1. Remove the inheritance of text transform in Firefox. */ button, select { /* 1 */ text-transform: none; } /** * Correct the inability to style clickable types in iOS and Safari. */ button, [type="button"], [type="reset"], [type="submit"] { -webkit-appearance: button; }

I was a tiny bit surprised to see WTF, Forms? not cover buttons, only because of how much weirdness there is. But the form elements that project whips into shape are even more notoriously difficult!

A Style-Testing Kinda Thingy

I feel like the answer to this is basically a big ol' block of CSS. That's what Andy provided, and you could very likely come to one on your own by just being a little heavier handed than the usual of setting style rules with your buttons.

Still, I felt compelled to make a little tester machine thingy so you can toggle styles on and off and see how they all go together in whatever browser you happen to be in:

See the Pen Consistent button styles by Chris Coyier (@chriscoyier) on CodePen.


The biggest point here is to use the correct native elements, as you get a bunch of functionality and accessibility for free. But you might as well get the styling right, too!

While we're talking buttons, I'm gonna use the same quote I used in our When To Use The Button Element post from MDN:

Warning: Be careful when marking up links with the button role. Buttons are expected to be triggered using the Space key, while links are expected to be triggered through the Enter key. In other words, when links are used to behave like buttons, adding role="button" alone is not sufficient. It will also be necessary to add a key event handler that listens for the Space key in order to be consistent with native buttons.

You don't need role="button" on <button> because they are already buttons, but if you're going to make any other element button-like, you have more work to do to mimic the functionality.

Plus, don't forget about :hover and :focus styles! Once you've wrangled in the styles for the default state, this shouldn't be so hard, but you definitely need them!

button:hover, button:focus { background: #0053ba; } button:focus { outline: 1px solid #fff; outline-offset: -4px; } button:active { transform: scale(0.99); }

The post Overriding Default Button Styles appeared first on CSS-Tricks.

Grid Level 2 and Subgrid

Css Tricks - Tue, 05/08/2018 - 3:56am

I find the concept of subgrid a little hard to wrap my mind around.

I do understand the idea that we want to use nested semantic markup as we like and have elements participate in one grid so we don't have to flatten our markup just for layout reasons. But that is largely handled by display: contents;.

Rachel Andrew explains it in a way that finally clicked for me:

I have an item spanning three column tracks of the grid, it is also a Grid Container with three column tracks - however these do not line up with the tracks of the parent...

If the nested grid columns were to be defined as a subgrid, we would use the subgrid value of grid-template-columns on that child element. The child would then use the three column tracks that it spanned, and its children would lay out on those tracks.

It's not that the parent disappears, it's that it shares grid lines with the parent so that getting internal elements to line up with everything else happens naturally.

Direct Link to ArticlePermalink

The post Grid Level 2 and Subgrid appeared first on CSS-Tricks.

Decorating lines of text with box-decoration-break

Css Tricks - Tue, 05/08/2018 - 3:49am

An institution’s motto, an artist’s intro, a company’s tagline, a community’s principle, a service’s greeting… all of them have one thing in common: they’re one brief paragraph displayed on a website’s home page — or at least the about page!

It’s rare that just one word or one line of text welcomes you to a website. So, let’s look at some interesting ways we could style the lines of a paragraph.

To see how things currently are, let’s try giving borders to all the lines of some text in an inline span and see how it looks:

<p><span>Hummingbirds are birds from...</span></p> span { border: 2px solid; }

See the Pen Broken inline box. by Preethi (@rpsthecoder) on CodePen.

The edges appear broken, which they technically are, as the inline box has been fragmented into multiple lines. But we can fix those broken edges with box-decoration-break!

The box-decoration-break property in CSS can decorate the edges of fragments of a broken inline box (as well as of a page, column, and region boxes).

Its value, clone, does that with the same design that appears in the box’s unbroken edges, and its default value, slice, does not copy the decorations at the edges, keeping the break very visible like you saw in the demo above.

Let’s try it:

span { border: 2px solid; box-decoration-break: clone; }

See the Pen Broken inline box w/ box-decoration-break. by Preethi (@rpsthecoder) on CodePen.

The property affects not only the border but also the shadow, spacing, and background of the broken edges.

Let’s play with the background first. While writing the post on knockout text, I was working with the background-clip property and wanted to see if the design held up for multiple lines of text. It didn’t.

The background gradient I applied was not replicated in every line, and after clipping it, only the first one was left with a background. That is, unless box-decoration-break: clone is added:

<p><span>Singapore:<br>Lion City</span></p> span { background-image: linear-gradient(135deg, yellow, violet); background-clip: text; color: transparent; padding: .5em; box-decoration-break: clone; }

See the Pen Gradient multi-line text w/box-decoration-break. by Preethi (@rpsthecoder) on CodePen.

The background-clip property with the text value clips a background to the shape of its foreground text. Since we used box-decoration-break, the gradient background is shown and clipped uniformly across all the lines of the text.

Going back to the border, let’s see how its shape and shadow can be copied across the broken edges, along with padding:

<img src="tree.png"> <p><span>Supertrees are tree-like structures...</span></p> <img src="tree.png"> <p><span>Supertrees are tree-like structures...</span></p> span { background: rgb(230,157,231); border-radius: 50% 0%; box-shadow: 0 0 6px rgb(41,185,82), 0 0 3px beige inset; padding: .5em 1.3em; box-decoration-break: clone; } p:nth-of-type(2) span { background-clip: content-box; }

See the Pen Inline border shape & shadow w/box-decoration-break. by Preethi (@rpsthecoder) on CodePen.

In the second paragraph of the demo, the background is cropped until the content box (background-clip: content-box). As you can see, the crop happens in the broken edges as well, because of box-decoration-break: clone.

Another way we can style borders is with images. You might see a gradient border around the lines of text below, covering the broken edges, if the browser you’re now using supports border-image and the application of box-decoration-break over its result.

<p><span>The Malaysia–Singapore Second Link...</span></p> span { border: 2px solid; border-image: linear-gradient(45deg, #eeb075, #2d4944) 1; background: #eef6f3; padding: .5em 1.3em; box-decoration-break: clone; }

See the Pen Inline border image w/ box-decoration-break. by Preethi (@rpsthecoder) on CodePen.

An additional behavior we can tap into for decorating individual lines is of outline's. In supported browsers, box-decoration-break can add an outline to every line of the text, including the broken edges, which is useful for creating bicolored dashed borders.

<p><span>Cloud Forest replicates...</span></p> span { outline: 2px dashed rgb(216,255,248); box-shadow: 0 0 0 2px rgb(39,144,198); background: #fffede; padding: .5em 1.3em; animation: 1s animateBorder ease infinite; box-decoration-break: clone; } @keyframes animateBorder{ to{ outline-color: rgb(39,144,198); box-shadow: 0 0 0 2px rgb(216,255,248); } }

See the Pen Inline outline w/ box-decoration-break. by Preethi (@rpsthecoder) on CodePen.

As observed in the demo, box-decoration-break withstands animation.

Besides borders and backgrounds, box-decoration-break can also manage shapes applied over elements. There is not much use for it in inline boxes, and is maybe better used in a column or page box, although the application is not yet widely supported in browsers.

But to show an example of what that does, let’s try applying the clip-path property to the span.

The property clip-path itself is only fully supported by Firefox, so only in it you might see an expected outcome. But following are two images: the results of applying a circular clip path over the span, without and with box-decoration-break.

span { clip-path: circle(50% at 202.1165px 69.5px); ... } Circular clip-path on a span span { clip-path: circle(50% at 202.1165px 69.5px); box-decoration-break: clone; ... } Circular clip-path on a span with box-decoration-break: clone

You’ll notice in the first image that the 50% radius value is derived from the width of the inline box (the longest line) where box-decoration-break is not used.

The second image shows how box-decoration-break: clone redefines the computed value for 50% by basing them on the widths of the individual lines while keeping the center same as before.

And here’s how the inset function of clip-path (an inset rectangle) applied over the span clips it without and with box-decoration-break:

span { clip-path: inset(0); ... } Inset clip-path on a span span { clip-path: inset(0); box-decoration-break: clone; ... } Inset clip-path on a span with box-decoration-break: clone

Without box-decoration-break, only a portion of the first line that matches the length of the shortest is visible, and with box-decoration-break: clone, the first line is fully visible while the rest of the box is clipped.

So, maybe if you ever want to show only the first line and hide the rest, this can come in handy. But, as I mentioned before, this application is more suitable for other types of boxes than ones that are inline. Either way, I wanted to show you how it works.

Browser Support

As we've seen here, box-decoraton-break can be super useful and opens up a lot of possibilities, like creating neat text effects. The property enjoys a lot support with the -webkit prefix, but is still in Working Draft at the time of this writing and lacks any support in Internet Explorer and Edge. Here's where you can vote for Edge support.

This browser support data is from Caniuse, which has more detail. A number indicates that browser supports the feature at that version and up.

DesktopChromeOperaFirefoxIEEdgeSafari69*1132NoNoTP*Mobile / TabletiOS SafariOpera MobileOpera MiniAndroidAndroid ChromeAndroid Firefox11.3*11all62*66*57 Wrapping Up

The box-decoration-break: clone copies any border, spatial, and background designs applied on a fragmented inline box’s unbroken edges to its broken ones. This creates an even design across all the lines of the text, decorating them uniformly and can be super useful for all those blurbs of text that we commonly use on websites.

The post Decorating lines of text with box-decoration-break appeared first on CSS-Tricks.

VS Code Can Do That?

Css Tricks - Mon, 05/07/2018 - 10:30am

Clever microsite from Burke Holland and Sarah Drasner that highlights some of VS Code's coolest features. All fifteen of them are pretty darn cool. Here's a few other compelling features I've seen people use/love:

Personally, I'm still on Sublime. I gave VS Code the college try last year but failed. I can't even remember why now, which means it's probably about time to try again. If it was slowness, maybe it was because I was using too many add-ons.

Direct Link to ArticlePermalink

The post VS Code Can Do That? appeared first on CSS-Tricks.

Microsites for Case Studies

Css Tricks - Mon, 05/07/2018 - 3:53am

A lot of y'all have personal sites. Personal sites with portfolios. Or you work for or own an agency where showing off the work you do is arguably even more important. Often the portfolio area of a site is the most fretted and hard to pull off. Do you link to the live projects? Screenshots? How many? How much do you say? How much of the process do people care about?

I'm afraid I don't have all the answers for you. I don't really do much freelance, work for an agency, or have a need to present work I've done in this way.

But! I tweeted this the other day:


Build your case studies as microsites. Then they can just live alone and don't have to be a drag when redesigning your site.

If the microsite gets old and stogy, the project you're talking about probably has too.

— Chris Coyier (@chriscoyier) April 25, 2018

I was out to lunch with Rob from Sparkbox recently. A few years back, we worked together on a redesign of CodePen, and a byproduct of that was a microsite about that process.

I remember working on that microsite. It wasn't a burden, it was kinda fun. We built it as we went, when all that stuff was fresh in our minds. Now that site is kind of a monument to that project. Nobody needs to touch it. It doesn't load some global stylesheet from a main website. It's a sub-domained microsite. It'll be useful as long as it's useful. When it's not anymore, stop linking to it.

I've also watched loads of people struggle with what to put in that portfolio and how to deal with case studies. I've watched it be a burden to people redesigning their site or building one for the first time. I've also looked at a lot of personal sites lately, and the default is certainly to work the portfolio into the site itself.

Maybe for some of you, making your case studies into these microsites will be a useful way to go!

The post Microsites for Case Studies appeared first on CSS-Tricks.

CSS Environment Variables

Css Tricks - Fri, 05/04/2018 - 11:05am

We were all introduced to the env() function in CSS when all that drama about "The Notch" and the iPhone X was going down. The way that Apple landed on helping us move content away from those "unsafe" areas was to provide us essentially hard-coded variables to use:

padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);

Uh ok! Weird! Now, nine months later, an "Unofficial Proposal Draft" for env() has landed. This is how specs work, as I understand it. Sometimes browser vendors push forward with stuff they need, and then it's standardized. It's not always waiting around for standards bodies to invent things and then browser vendors implementing those things.

Are environment variables something to get excited about? Heck yeah! In a sense, they are like a more-limited version of CSS Custom Properties, but that means they can be potentially used for more things.

CSS environment variables are getting standardized:
Allow to get and use the browser- and author-defined variables: typography, colors, notch and other specific layout/device values.
They work in Media Queries, where CSS Custom Properties cannot be used.

— Serg Hospodarets (@malyw) April 29, 2018

&#x1f440; Brand new spec for global env() variables in CSS:

Forget notches, the important thing here is the ability to separate CSS variables from the cascade. Cool ? for perf/code organization ? because you might be able to use them in media queries!

— Eric Portis (@etportis) April 30, 2018

Eric also points out some very awesome early thinking:

ISSUE 4 - Define the full set of places env() can be used.

  • Should be able to replace any subset of MQ syntax, for example.
  • Should be able to replace selectors, maybe?
  • Should it work on a rule level, so you can insert arbitrary stuff into a rule, like reusing a block of declarations?

Probably still changeable-with-JavaScript as well. I would think the main reason CSS Custom Properties don't work with media queries and selectors and such is because they do work with the cascade, which opens up some very strange infinite loop logic where it makes sense CSS doesn't want to tread.

If you're into the PostCSS thing, there is a plugin! But I'd warn... the same issues that befall preprocessing CSS Custom Properties applies here (except the first one in that article).

The post CSS Environment Variables appeared first on CSS-Tricks.

Inspecting Animations in DevTools

Css Tricks - Fri, 05/04/2018 - 3:57am

I stumbled upon the Animation panel in Chrome’s DevTools the other day and almost jumped out of my seat with pure joy. Not only was I completely unaware that such a thing exists, but it was better than what I could’ve hoped: it lets you control and manipulate CSS animations and visualize how everything works under the hood.

To access the panel, head to More Tools ? Animations in the top right-hand menu when DevTools is open:

Many of the tutorials I found about this were pretty complicated, so let’s take a step back and look at a smaller example to begin with: here’s a demo where the background-color of the html element will transition from black to orange on hover:

html { cursor: pointer; background-color: #333; transition: background-color 4s ease; } html:hover { background-color: #e38810; }

Let’s imagine that we want to nudge that transition time down from 4s. It can get pretty annoying just bumping that number up and down in the element inspector. I typically would’ve opened up DevTools, found the element in the DOM and then ever-so-slowly manipulate it by typing in a value or using the keyboard directional keys. Instead, we can fire up that demo, open DevTools, and switch to the Animation tab which ought to look something like this:

By default, Chrome will be "listening" for animations to take place. Once they do, they’ll be added to the list. See how those animation blocks are displayed sort of like an audio wave? That’s one frame, or act, of an animation and you can see on the timeline above it each frame that follows it. On an animation itself, the inspector will even show us which property is being changed, like background-color or transform. How neat is that?

We can then modify that animation by grabbing that bar and moving it about:

...and it updates the animation right away — no more clicking and editing an animation the old way! Also, you might’ve noticed that hovering over an animation frame will highlight the element that’s being animated in blue. This is handy if you’re editing a complex animation and forget what that crazy weird pseudo element does. If you have multiple animations on a page, then you can see them all listed in that section just like in this demo:

What we’re doing here is animating both the .square and the .circle when hovering on the html element, so there’s effectively two separate divs being animated in the same time frame — that’s why you can see them in the same section just like that.

I can see that inspecting animations in this way could be super useful for tiny icon design, too. Take this pen of Hamburger menu animations by Jesse Couch where you might want to slow everything down to get things just right. Well, with the animation inspector tool you can do exactly that:

Those buttons in the top left-hand corner will control the playback speed of the animation. So hitting 10% will slow things to a crawl — giving you enough time to really futz with things until they’re perfect.

I’ve focused on Chrome here but it’s not the only browser with an animation inspector — Firefox’s tool is in every way just as useful. The only immediate difference I found was that Chrome will listen for any animations on a page and will display them once their captured. But, with Firefox, you have to inspect the element and only then will it show you the animations attached to that element. So, if you’re doing super complex animations, then Chrome’s tool might be a smidge more helpful.

Animation Inspector Documentation

The post Inspecting Animations in DevTools appeared first on CSS-Tricks.

Syndicate content
©2003 - Present Akamai Design & Development.