Skip to content
This repository was archived by the owner on Nov 30, 2021. It is now read-only.

Commit 730b6d0

Browse files
authored
Merge pull request alphagov#683 from alphagov/assets-guidance
Add guidance for CSS, JavaScript and images
2 parents cc8d92a + 02226d1 commit 730b6d0

3 files changed

Lines changed: 85 additions & 26 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Adding CSS, JavaScript and Images
2+
3+
The Prototype Kit comes with standard GOV.UK Frontend styles and components for you to use in your prototypes. However if you need to add your own CSS (Cascading Style Sheets), JavaScript or images, use the `/app/assets` folder.
4+
5+
The Prototype Kit processes all the files in the `/app/assets` folder, and puts the processed files in `/public`.
6+
7+
Do not change files in the `/public` folder because it’s deleted and rebuilt every time you make a change to your prototype.
8+
9+
## CSS
10+
11+
CSS lets you change how web pages look, for example text sizes, colours or spacing.
12+
13+
To add styles use:
14+
15+
```
16+
/app/assets/sass/application.scss
17+
```
18+
19+
Do not edit the file `/public/styles/application.css` because it’s deleted and rebuilt every time you make a change to your prototype.
20+
21+
The Prototype Kit uses [Sass](https://sass-lang.com/guide), which adds extra features to CSS.
22+
23+
### Using import
24+
25+
If you have a very long application.scss file, you can split it up into multiple files and import those into `application.scss`. Use an underscore (_) at the start of the import file filenames, for example:
26+
27+
```
28+
/app/assets/sass/_admin.scss
29+
```
30+
31+
Import this file into your `application.scss` file without the underscore:
32+
33+
```
34+
@import "admin";
35+
```
36+
37+
## JavaScript
38+
39+
You can use JavaScript to make changes to a web page without loading a new one. For example a user could enter some numbers, then JavaScript displays the results of a calculation without loading a new page.
40+
41+
To add JavaScript use:
42+
43+
```
44+
/app/assets/javascripts/application.js
45+
```
46+
47+
Do not edit the file `/public/javascript/application.js` because it’s deleted and rebuilt every time you make a change to your prototype.
48+
49+
## Images
50+
51+
If you add images to `/app/assets/images` the Prototype Kit will copy them to `/public`.
52+
53+
For example if you add an image:
54+
55+
```
56+
/app/assets/images/user.png
57+
```
58+
59+
Use it in your page like this:
60+
61+
```
62+
<img src="/public/images/user.png" alt="User icon">
63+
```
64+
65+
Use ‘alt’ text to describe the image for screen readers.
66+
67+
Do not put files directly in `/public` because it’s deleted and rebuilt every time you make a change to your prototype.
68+
69+
## Other files
70+
71+
If you need to use other files in your prototype, you can add them to `/app/assets` and the Prototype Kit will copy them to `/public`. You can use sub-folders in the assets folder.
72+
73+
For example if you add a PDF:
74+
75+
```
76+
/app/assets/downloads/report.pdf
77+
```
78+
79+
Link to it like this:
80+
81+
```
82+
<a href="/public/downloads/report.pdf">Download the report</a>
83+
```
84+
Do not put files directly in `/public` because it’s deleted and rebuilt every time you make a change to your prototype.

docs/documentation/writing-css.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/views/tutorials-and-examples.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ <h3 class="govuk-heading-s">Basic usage</h3>
6464
<a href="/docs/making-pages">Making pages</a>
6565
</li>
6666
<li>
67-
<a href="/docs/writing-css">Writing CSS</a>
67+
<a href="/docs/adding-css-javascript-and-images">Adding CSS, JavaScript and Images</a>
6868
</li>
6969
<li>
7070
<a href="/docs/setting-up-git">Setting up Git</a>

0 commit comments

Comments
 (0)