|
| 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. |
0 commit comments