Just like in HTML, you can add a <style>
tag to your component. Let's add some styles to the <p>
element:
<style>
p {
color: purple;
font-family: 'Comic Sans MS', cursive;
font-size: 2em;
}
</style>
<p>This is a paragraph.</p>
Importantly, these rules are scoped to the component. You won't accidentally change the style of <p>
elements elsewhere in your app, as we'll see in the next step.
App.svelte
xxxxxxxxxx
5
1
<style>
2
/* styles goes here */
3
</style>
4
5
<p>This is a paragraph.</p>
Console
xxxxxxxxxx
39
1
/* App.svelte generated by Svelte v3.23.2 */
2
import {
3
SvelteComponent,
4
detach,
5
element,
6
init,
7
insert,
8
noop,
9
safe_not_equal
10
} from "svelte/internal";
11
12
function create_fragment(ctx) {
13
let p;
14
15
return {
xxxxxxxxxx
39
1
/* App.svelte generated by Svelte v3.23.2 */
2
import {
3
SvelteComponent,
4
detach,
5
element,
6
init,
7
insert,
8
noop,
9
safe_not_equal
10
} from "svelte/internal";
11
12
function create_fragment(ctx) {
13
let p;
14
15
return {
Compiler options
result = svelte.compile(source, {
generate:
});xxxxxxxxxx
1
1
/* Add a <style> tag to see compiled CSS */
xxxxxxxxxx
1
1
/* Add a <style> tag to see compiled CSS */