\n

```
Here, clicking the button changes the background color of the div. This method works for directly applying or modifying individual CSS properties.

\n

\n

2. Manipulating CSS Classes
Rather than directly manipulating individual CSS properties, a more maintainable approach is to add, remove, or toggle CSS classes using JavaScript. This way, you keep all your styles in a CSS file and simply tell JavaScript to apply or remove those classes.

\n

```

\n

\n

\n

```
Here, we use classList.toggle to switch between light and dark mode. This method is more scalable and easier to maintain because your styles are kept in CSS files.

\n

\n

3. Responsive Design
CSS variables (–custom-property) allow you to define dynamic values that can be updated through JavaScript, making it an effective way to handle themes and responsive styles.

\n

```





\n

```

\n

In this example, we use JavaScript to update a CSS variable (–box-color) that controls the background color of the box. This approach is excellent for creating theme-able and responsive designs.

\n

\n

By combining CSS and JavaScript, you can build interactive user interfaces that react to user input and adapt to changing conditions. Remember to choose the right approach based on your use case. For simple changes, inline styles might suffice. For more scalable, maintainable code, manipulating CSS classes is the way to go. And if you need complete control, modifying CSS variables can offer flexibility.

\n

Happy coding!

\n

\n

🤙 the Slater Team

\n

\n

\n

If Slater helps you create better websites, please support the team behind it.

\n
Become a Pro Slater User
\n\n\n\n","recentPosts":[{"id":7318105,"title":"📈 Slater and marketing and data","slug":"slater-and-marketing-and-data","status":"published","readingTime":2,"campaignCompletedAt":"2024-11-22T23:42:53.000Z","publishedAt":"2024-11-22T23:42:53.000Z","orderByDate":"2024-11-22T23:42:53.000Z","timeAgo":"9 days","thumbnailUrl":"https://embed.filekitcdn.com/e/f2wTcXHNz6CCWc9a5vGTv3/83K6btRYEzGpKw3N7Ed3YS/email","thumbnailAlt":"","path":"posts/slater-and-marketing-and-data","url":"https://slater.kit.com/posts/slater-and-marketing-and-data","isPaid":null,"introContent":"👋, In August, we launched a novel approach to a marketing site with ask.edgarallan.com. Since then, we've been focused on determining whether we built a winner or a loser by refining our data analytics capabilities. So far, the results look promising: check out this update. Alongside ask.ea, we’re also enhancing our data analytics for Slater.app. What does that mean? Over the next several months, we’ll be rolling out updates based on your feedback and user data. Stay tuned—we’ll share our...","campaignId":17366913,"publicationId":13912429},{"id":7244528,"title":"📚 Edgar Allan released a new book","slug":"edgar-allan-released-a-new-book","status":"published","readingTime":1,"campaignCompletedAt":"2024-11-15T21:34:27.000Z","publishedAt":"2024-11-15T21:34:27.000Z","orderByDate":"2024-11-15T21:34:27.000Z","timeAgo":"16 days","thumbnailUrl":"https://embed.filekitcdn.com/e/f2wTcXHNz6CCWc9a5vGTv3/vi7rPU2yfWxR3ACeZufzXM/email","thumbnailAlt":"","path":"posts/edgar-allan-released-a-new-book","url":"https://slater.kit.com/posts/edgar-allan-released-a-new-book","isPaid":null,"introContent":"We’re taking a break from our usual JavaScript content to share some exciting news: Edgar Allan has released a new book, How to Grow & Scale Your Business With Webflow. Created in collaboration with Webflow, this book is a must-read for anyone building a business with Webflow. Filled with insights from 3x Agency of the Year winner Edgar Allan, it’s a playbook for individuals, pro-lancers, and small agencies growing alongside the revolutionary site-building platform. For our Slater users, we...","campaignId":17275642,"publicationId":13820005},{"id":7174182,"title":"🤲 Help us help you","slug":"help-us-help-you","status":"published","readingTime":2,"campaignCompletedAt":"2024-11-08T20:13:12.000Z","publishedAt":"2024-11-08T20:13:12.000Z","orderByDate":"2024-11-08T20:13:12.000Z","timeAgo":"23 days","thumbnailUrl":"https://embed.filekitcdn.com/e/f2wTcXHNz6CCWc9a5vGTv3/5JPAKp6PMbAzSfhn3hLd8x/email","thumbnailAlt":"","path":"posts/help-us-help-you","url":"https://slater.kit.com/posts/help-us-help-you","isPaid":null,"introContent":"Slater now has 7389 users. 2060 of you haven't created a file yet. 😱 These numbers got us thinking – we want to make Slater easier and more helpful to all #nocode developers.We’d love to hear from you: Did you find it challenging to get started with Slater? Are there specific areas where you could use more guidance? Do you use JavaScript often in your Webflow projects? Or is Slater your first time exploring custom code? What would help you feel more confident writing JavaScript in Slater? Are...","campaignId":17192404,"publicationId":13736524}],"newsletter":{"formId":4967504,"productId":null,"productUrl":null,"featuredPostId":null,"subscribersOnly":false},"isPaidSubscriber":false,"isSubscriber":false,"originUrl":"https://slater.kit.com/posts/slater-css","creatorProfileName":"Welcome To Slater!","creatorProfileId":1135261}👩🏼‍🎨 Slater & CSS

👩🏼‍🎨 Slater & CSS


Do you use Slater for CSS? CSS support in Slater has always been somewhat of an afterthought—JavaScript is our love language! But sometimes, you need a simple way to add CSS to your project. Maybe you want to write a complex grid or use a CSS property that Webflow doesn't support. That's why we've decided to make CSS a first-class citizen.

We considered launching the new CSS functionality today, but we want to test it a bit more. Expect it early next week.

To prepare for the launch, let's highlight 3 CSS solutions found in the Community Library:

Community Library

🫵 Pointer events
​CSS classes to control pointer events: .pointer-events-off disables interactions, .pointer-events-on enables interactions.

Ellipsis text
CSS class to truncate text with ellipsis when it overflows the container width.

📜 Hide scrollbars
CSS class to hide scrollbars

Have you added a useful script to your library? Share it with us!

--

Javascript 101: CSS & JS

Let's stay on the subject of CSS. Combining CSS and JavaScript is a important way to create dynamic websites. In many cases, you’ll want to modify styles using JavaScript, either in response to user input or to create smooth animations. Let's look at some examples of how you can do this.

1. Inline Styles
The easiest way to manipulate CSS with JavaScript is by modifying the inline styles of an element directly using the style property.

```
<button id="colorBtn">Change Background</button>
<div id="box" style="width: 100px; height: 100px; background-color: lightblue;"></div>

<script>
const button = document.getElementById('colorBtn');
const box = document.getElementById('box');

button.addEventListener('click', () => {
box.style.backgroundColor = 'tomato';
});
</script>

```
Here, clicking the button changes the background color of the div. This method works for directly applying or modifying individual CSS properties.

2. Manipulating CSS Classes
Rather than directly manipulating individual CSS properties, a more maintainable approach is to add, remove, or toggle CSS classes using JavaScript. This way, you keep all your styles in a CSS file and simply tell JavaScript to apply or remove those classes.

```
<button id="toggleBtn">Toggle Dark Mode</button>
<div id="box" class="light-mode"></div>

<style>
.light-mode {
background-color: lightgray;
width: 100px;
height: 100px;
}
.dark-mode {
background-color: black;
color: white;
}
</style>

<script>
const toggleButton = document.getElementById('toggleBtn');
const box = document.getElementById('box');

toggleButton.addEventListener('click', () => {
box.classList.toggle('dark-mode');
});
</script>

```
Here, we use classList.toggle to switch between light and dark mode. This method is more scalable and easier to maintain because your styles are kept in CSS files.

3. Responsive Design
CSS variables (–custom-property) allow you to define dynamic values that can be updated through JavaScript, making it an effective way to handle themes and responsive styles.

```
<style>
:root {
--box-color: pink;
}
.variable-box {
width: 100px;
height: 100px;
background-color: var(--box-color);
}
</style>

<div class="variable-box"></div>
<button id="changeColor">Change Color</button>

<script>
const button = document.getElementById('changeColor');

button.addEventListener('click', () => {
document.documentElement.style.setProperty('--box-color', 'skyblue');
});
</script>

```

In this example, we use JavaScript to update a CSS variable (–box-color) that controls the background color of the box. This approach is excellent for creating theme-able and responsive designs.

By combining CSS and JavaScript, you can build interactive user interfaces that react to user input and adapt to changing conditions. Remember to choose the right approach based on your use case. For simple changes, inline styles might suffice. For more scalable, maintainable code, manipulating CSS classes is the way to go. And if you need complete control, modifying CSS variables can offer flexibility.

Happy coding!

🤙 the Slater Team

If Slater helps you create better websites, please support the team behind it.

Welcome To Slater!

Slater resources, updates and community activity

Read more from Welcome To Slater!

👋, In August, we launched a novel approach to a marketing site with ask.edgarallan.com. Since then, we've been focused on determining whether we built a winner or a loser by refining our data analytics capabilities. So far, the results look promising: check out this update. Alongside ask.ea, we’re also enhancing our data analytics for Slater.app. What does that mean? Over the next several months, we’ll be rolling out updates based on your feedback and user data. Stay tuned—we’ll share our...

We’re taking a break from our usual JavaScript content to share some exciting news: Edgar Allan has released a new book, How to Grow & Scale Your Business With Webflow. Created in collaboration with Webflow, this book is a must-read for anyone building a business with Webflow. Filled with insights from 3x Agency of the Year winner Edgar Allan, it’s a playbook for individuals, pro-lancers, and small agencies growing alongside the revolutionary site-building platform. For our Slater users, we...

Slater now has 7389 users. 2060 of you haven't created a file yet. 😱 These numbers got us thinking – we want to make Slater easier and more helpful to all #nocode developers.We’d love to hear from you: Did you find it challenging to get started with Slater? Are there specific areas where you could use more guidance? Do you use JavaScript often in your Webflow projects? Or is Slater your first time exploring custom code? What would help you feel more confident writing JavaScript in Slater? Are...