extension WKWebView { //via https://stackoverflow.com/a/53706678 //and https://stackoverflow.com/a/53141055 func applyStylesheet() { guard let path = Bundle.main.path(forResource: "style", ofType: "css"), //load style.css from your app bundle let cssString = try? String(contentsOfFile: path).components(separatedBy: .newlines).joined() else { return } let source = """ var style = document.createElement('style'); style.innerHTML = '\(cssString)'; document.head.appendChild(style); """ let userScript = WKUserScript(source: source, injectionTime: .atDocumentEnd, forMainFrameOnly: true) self.configuration.userContentController.addUserScript(userScript) } }