Elements protected by copyright, such as images, text or source code, cannot be duplicated. It is illegal to use any person’s logo or registered material.
You can take inspiration from a number of websites and incorporate them into your web design. It is legal to recreate items that are similar to those on another site with custom code. You are never allowed to copy and paste code from an open source project directly into proprietary code. On a technical level, every time you read the site, you make a copy of the site’s client-side code so that you can run it.
If the code is NOT published in open source mode, it is definitely illegal to use it directly on your own site. Sometimes you can contact the website owner and request that the page or pages be removed. If it’s a single page or a few design elements, there is likely a contact form on the website that you can use and they are ready to work with you.