📣 Announcing:
🔋 StackBlitz Self-Hosted! 🔋
Integrate it with your internal systems and scale productivity without hiking hosting costs!
Now you can finally bring secure, fast, in-browser web development environments to your enterprise, on prem!
Today we’re excited to bring Node.js back to its roots - the browser!
Together with
@googlechrome
and
@vercel
, we're enabling a new type of development and debugging experience that was not possible before: 🧵
🎨 CSS tip(3):
`height: 100vh`
is a common way to make your app fit the whole window. It won't do a good job on mobile though 😬
`height: 100dvh`
works way better!
📱 See the difference on your phone:
💻 Play with the demo:
#CSS
tip (8):
You can implement a snap effect for scrollable content on your site with just 2 lines of CSS!
1️⃣ `scroll-snap-type` on parent
2️⃣ `scroll-snap-align` on children
💻 Play with the code:
#CSS
tip (5):
Using a blur filter you can create a very nice backlight (or a "smart shadow") effect for your images.
In a pseudo-element:
1⃣ `inherit` a background
2⃣ blur it
3⃣ put it behind the main element using z-index
💻 Play with the code:
Today, after years of battle testing by millions of developers, in collaboration with browser vendors:
WebContainer API is now available to everyone.
Start building the next generation of interactive coding experiences at ❤️🧵
💡 JavaScript tip (11):
When dealing with numeric inputs – such as number, range, or date – you can use the `.valueAsNumber` property to get an actual number instead of a string (that the `.value` returns.)
A suddenly-appearing scrollbar can shift a layout… but now you can use `scrollbar-gutter: stable` to mitigate that! 😍
💻 You can play with the demo here:
📘 Read the MDN docs:
🌐 Browser support: Chrome, Edge, Firefox
[1/2]
Argh, a scrollbar shows and the whole page shifts!
We've all seen that, right? 😅
You might know that `overflow-y: scroll` mitigates the issue by showing scrollbar all the time.
But now there's a more elegant solution:
`scrollbar-gutter: stable` just reserves the space!
📢 Announcing:
WebContainers are now officially supported in Firefox, desktop & mobile!
You can now build Node.js apps directly in the browser using
@Firefox
and debug them natively with
@FirefoxDevTools
🔥
> Use the Web to Build the Web! <
💡 Optimization tip (3):
By adding the `defer` attribute to your `<script>` tag, you make that JavaScript run only _after_ the DOM is loaded, so it doesn't delay displaying the page itself.
Is there an actual difference? Let's see:
The Node.js runtime itself is running natively, inside the browser, for the first time ever:
(Note: this environment *is not* running on a remote server!)
💡 UX improvement tip (2):
By setting `scroll-behavior` in your CSS to `smooth`, you can help users notice scrolling happened.
⚠️ Remember about those who prefer reduced motion though! (see end of the video)
#CSS
tip (2):
`place-items` is a shorthand property that allows you to e.g. center what's inside a `grid` container.
Super useful if you're confused about `align-items`, `align-content`, `justify-content`, `justify-items`… and all you wanted was just to center stuff 😁
What HTML element do you feel is still not used enough these days?
How about `<details>` - for doing this common "show more" feature in a nice semantic way, and with no JavaScript needed?
#useThePlatform
💪
Browsers are awesome! (4):
`window.showOpenFilePicker()` allows you to read from, and write to local files! 🤯
So.. how about we use an online code editor to build an online text editor? 😁
Let's start with file syncing:
💡 Forms tip! (3)
Use `<datalist>` to enhance your forms with suggested values – not only for text inputs, but also 🧮 numbers, 📏 ranges, ✉️ emails, and even 🚦 colors!
#useThePlatform
💡 JavaScript tip (12):
If you only want to handle an event once, you can configure this with the 3rd argument to the `addEventListener` method: `{ once: true }`
💡 JavaScript tip (7):
`Array.includes` is useful in removing repeat logic.
Instead of:
"if A is this, or A is that, or A is that, or that"
... you're writing:
"if A is among these values"
CSS tip:
Are your numbers jumpy? That's because each digit can have a different width. This causes issues ranging from an unpleasant visual effect in a counter component to layout shifts in your UI 😬
To fix this, use `font-variant-numeric` and `font-feature-setting`:
💡 Forms tip! (5)
`autocomplete="one-time-code"` can help users auto-fill the auth code they've just received - they won't need to copy it from the SMS by hand!
💡 TypeScript tip (4):
Keeping your objects immutable is often important for
- performance (e.g. Redux or `onPush` in
@Angular
)
- and sane logic (e.g. don't wanna mutate default values)
You can make your object read-only (nested!) by adding `as const` assertion:
#HTML
tip (3):
When working with ordered lists, you can use the `reversed` and `start` attributes!
💡 Perfect for counting down and pagination!
(💻 demo: )
💡 JavaScript tip (10):
☑ You can set a checkbox to `checked` state via JavaScript or with an HTML attribute.
But...
🤷 You can also set it to an `indeterminate` state – with JavaScript only.
Useful e.g. when you have an option with sub-options that are partly selected.
💡 JavaScript i18n / l10n tip (3):
`Intl` is a powerful API (supported by all modern browsers) that helps to deal with all things languages-related – no external lib necessary!
Here's how to use `Intl.RelativeTimeFormat()` to display relative time:
#useThePlatform
This popped up on my timeline, so decided to give it a go and run
@debs_obrien
's Nuxt Content tutorial in a web container.
A minute later it's up and running! ♥️
... and we don't officially support
@nuxt_js
yet 😃
My Vue friends will be so happy! ☺️
💡 JavaScript tip (13):
If you want to test something quickly in your browser's console and you need `document.querySelectorAll` for it, DevTools provide a handy `$$` function – just for that.
#CSS
tip:
`text-decoration` doesn't have to mean a solid line:
You can make it dotted, dashed, double, or even wavy!
And even change its color & thickness too!
(Useful e.g. for making your texts pop visually without making them look like links)
`<two-up>` is a custom element you can use to add a visual comparison feature to any website/app:
1⃣ `import 'two-up-element'` (or use a cdn link)
2⃣ use `<two-up>` around any two HTML elements
3⃣ that's it, enjoy!
Web Components are awesome!
#useThePlatform
Introducing: StackBlitz Codeflow! ♾
Codeflow is a one-click GitHub integration that keeps you in flow state by seamlessly weaving together:
- creating & reviewing pull requests
- fixing issues
- contributing to open-source repositories
in a way that wasn't possible before: 🧵
#CSS
tip (4):
🖨️ Links don't make any sense when a page is printed out.
(we tried tapping, even double-tapping the paper... nothing!😮)
You can make them way more informative though:
💡 Use `content: attr(href)` to automatically add links' addresses in the print stylesheet.
CSS is awesome:
You can implement a snap effect with just 2 CSS properties!
1️⃣ `scroll-snap-type` on parent
2️⃣ `scroll-snap-align` on children
💻 Play with the code:
📘 Read the MDN docs:
🌐 Browser support: full!:)
#HTML
Tip (2):
<dialog> is the web's modal. Includes the open attribute, ::backdrop pseudo-element and a native way to close with <form method="dialog">.
⚡️ Combine with <details>, <summary>, and a little JS to make a nice semantic modal without CSS.
Vertical centering for `display: block` is coming to a browser near you!
`align-content: center` is now supported in Chrome 123, Safari 17.4 beta, and in development in Firefox 🥳
💡 JavaScript tip (6):
Have you ever written `v => console.log(v)` to quickly find out what comes in a callback? There's a more convenient way:
Just use `console.log` directly!
(it's not only less typing, but also "automatically" gets all the params, if there's more than one)
💡 Optimization tip (2):
The HTML `<picture>` element allows us to provide images in several formats, and because it has a fallback mechanism built-in, each browser displays only the source it supports.
Like here: Chrome gets .avif, Firefox – .webp (& guess who'll get .jpg 😉)
💡 Forms tip! (9)
`:focus-within` pseudoclass allows to style a container that contains a focused element.
You can use it to e.g. put more emphasis on a fieldset a user is filling at a certain moment.
Our team is obsessed with speed, so when we've heard the latest
@Vite_js
2.9 significantly optimizes cold start (+more!), we had to put it to the test. Well… wow 🤯
💡 TypeScript tip (7):
Using the built-in `Partial<T>` you can create a new type with all the properties of your base type (<T>) set to optional – useful for update logic and writing tests.
The opposite is `Required<T>`, which makes all the properties, well, required 😀
So, you can now build your next slide deck with code...
but with no need for any manual setup, or even leaving the browser!
Just open a new tab, type , and jump in to focus on your presentation 😍
💡 Need an instant backend for your demo, prototype or workshop?
With `json-server` (
@typicode
♥️) you can have a REST API in literally 5 seconds!
You get GET, POST, DELETE, pagination, sorting, full-text search, and others out of the box 🤯
(+ it works great in WebContainers!)
💡 Forms tip! (10)
As most JavaScript developers quickly learn, values read from `<input type="number">` are actually... strings! – which leads to some funky results when using them in math operations.
But if you use `.valueAsNumber` instead – you get actual JavaScript numbers!
💡 JavaScript tip (2):
When dealing with big numbers in JS, instead of typing a bunch of zeros, you can use either:
- scientific notation (e.g. 10e6) or
- numeric separator (e.g. 10_000_000)
`aspect-ratio` is now supported by all major browsers! 🤩
💻 You can play with this demo here:
📘 Read the MDN docs:
🌐 Browser support:
Edge, Chrome, Firefox, Safari, Android Browser… pretty much everything but the IE;)
💡 Forms tip! (2)
You *can* customize these native html validation messages that browsers display. Just use the `setCustomValidity` method!
Super useful for working with pattern validation, or even just to say "Name is required" ;)
#useThePlatform
#HTML
Tip:
💬 Build a video chat using Web RTC and the MediaCapture/Streams APIs.
🔎 First step: capturing video through the MediaCapture API using navigator.mediaDevices.getUserMedia and the <video> tag.
🤳 Now the user can see how others see them!
💡 Forms tip! (4)
The `<fieldset>` element – used for grouping relevant inputs & buttons – allows you to provide the `disabled` attribute if you want to disable these enclosed controls all at once.
#useThePlatform
💡 JavaScript i18n / l10n tip (5):
Adding suffixes to ordinal numbers ("1st, 14th, ...") used to require lots of error-prone custom logic (specific for each locale!)
Nowadays you can use `Intl.PluralRules` instead:
📢 Announcing: *Nuxt support on StackBlitz!* 🎉
We are thrilled to have worked with
@Nuxt_js
to bring you *the fastest way* to start your next awesome
@vuejs
application – right in your browser!
Can't wait to see what you'll build with it!
#CSS
tip (6):
❄ Using a backdrop-filter, you can create a frosted glass effect (as seen in many native apps). It adds a layer of depth and is a really nice touch to a design. 💅
🎨 CSS tip(4):
`:has` selector allows you to select a parent of a given element…
… but it can also select a sibling that appears BEFORE a specific condition! 🤯
💻 Play with the demo:
💡 Forms tip! (7)
Working with date inputs use the `valueAsDate` property so you don't have to manually convert between "YYYY-MM-DD" string and a `Date` object.
ℹ️ Useful for both getting, and settings the value!
💡 JavaScript i18n / l10n tip (2):
Use `.toLocaleString()` method to display dates in language-specific format.
You can also set additional options such as timezone or 12- vs 24-hour format.
No external lib necessary!
#useThePlatform
💡 TypeScript tip (5):
The `keyof` operator extracts the keys of a given type, which makes it extremely useful for all kinds of logic that's based on properties of an object – like sorting, filtering, etc.
💡 Combine it with a generic type to make it more universal!
Browsers are awesome! (3):
`<input type="file">` permits a user to select only a single file at a time... but that's only its default behavior!
You can also allow selecting multiple files, and even specify the supported file types!
Just add `multiple` and `accept` attributes:
That was fast! You can now try Nuxt 3 Beta, powered by
@vite_js
, entirely inside your browser 🎉
Thanks
@Atinux
&
@nuxt_js
team for making this happen so quickly!
Try it out 👉
Need the "[n] hours ago" info on your page?
1⃣ - add the `<relative-time>` element
2⃣ - and the script tag
... done!
GitHub's `time-elements` need way more recognition! 😍
(see it in action: )
💡 Forms tip!
Use the built-in `.validationMessage` property that allows you to get a native validation message (in your user's locale!), and display it in the UI the way you like it.
Way less hardcoded logic too!
#useThePlatform
📣 A little surprise for the
@Sveltejs
community ahead of
#SvelteSummit
:
We're excited to announce the official support for SvelteKit in WebContainers!
💡 TypeScript tip:
TypeScript infers array's type as an Array of the union of included types... which may not be precise enough.
If you want this value to be inferred as a Tuple instead, add `as const`
#CSS
tip (11):
The hexadecimal color notation allows specifying the "alpha" value too!
(So if you're already using #-hex format there's no need to change it just to add a little transparency 🙂)
💡 UX improvement idea:
By changing input type from `text` to `search` you allow your users to quickly clear the value – which can be really useful for all kinds of search or filter elements.
demo:
(browser support is stellar btw! 💪
#UseThePlatform
)
💡 JavaScript i18n / l10n tip (6*):
Working with different units can be confusing!
`Intl.Units` object helps make sense of different systems of measurements – including the exotic ones: