Please enable JavaScript to use CodeHS

Demos

Music Library


Use CSS to style a music library.

Upload a File


## Attach a File for Upload Using an input field and JavaScript, you can attach files for upload. In this example, check out the code and try attaching multiple files. `<input type="file" id="file-selector" multiple style="padding:2em">` You can also change the code to only allow certain file types. When you're finished testing out the attachment input, add the following attribute to limit the file types a user can attach/upload. `accept=".jpg, .jpeg, .png"`

XSS and Code Injection


Cross-site scripting can be prevented by escaping characters. One way to do this is by using the HTML5 `pattern` attribute in the `<input>` tag. In this example, run the code and enter a JavaScript alert into the text input field. Select OK to see what happens. Example Alert JavaScript Code: `<script>alert("You've been hacked!")</script>` Then protect the website from code injection by adding a `pattern` attribute similar to the one shown in the `<input>` tag below: ```html <input type = "text" name = "username" id = "user" placeholder = "username" pattern="[^<>;/]+"> ``` Lastly, run the new code and try out your escaping technique by entering safe and unsafe characters in the text input. Did you receive an error message when you tried to submit a character not allowed? Did the input accept safe entries you tried?